How do I keep the trailing zero (or zeros) when I round with Excel VBA? -


the title says all. consider following example:

option explicit  sub roundtodecimalsdefinedbyenduser()     dim decimnum integer     decimnum = inputbox("how many decimals want?", "enter")     cells(1, 1).value = application.worksheetfunction.round(cells(1, 1).value, decimnum) end sub 

consider situation end user wants have 2 decimals, , number rounded 0.10111. result should 0.10, excel forces result 0.1. suggestions on how keep trailing zero(s)?

consider:

option explicit  sub roundtodecimalsdefinedbyenduser()     dim decimnum double, wf worksheetfunction     set wf = application.worksheetfunction     decimnum = inputbox("how many decimals want?", "enter")     cells(1, 1)       .value = wf.round(.value, decimnum)       .numberformat = "0." & wf.rept("0", decimnum)     end end sub 

this leave a1 numeric value.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -