Can I prevent rounding with the Format command?

USAMax

Well-known Member
Joined
May 31, 2006
Messages
849
Office Version
  1. 365
Platform
  1. Windows
I need to return a value with five decimal places.

If a value is 1.999999, the Format command returns 2.
var = 1.999999
debug.print Format(var, "#.00000")

Returns 2

I need it to return 1.99999

Mathematically I can change the value but there has got to be a better way. Can rounding be disabled?

This value can be multiplied by as much as a million so it does mater. I know 2 is closer to the original value but this is what they want.

Thank you.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I think your format line is short one zero after the decimal place. Try:

debug.print Format(var, "#.000000")

which matches the number of decimal places in your variable.
 
Upvote 0
I need to return a value with five decimal places.

If a value is 1.999999, the Format command returns 2.
var = 1.999999
debug.print Format(var, "#.00000")

Returns 2

I need it to return 1.99999
I don't think you should be using Format for what you are trying to accomplish. I think you should be using this to get five decimal places without rounding...

Debug.Print Int(100000*Value)/100000
 
Upvote 0
I think JoeMo nailed the problem.
:confused: The OP said...

"I need to return a value with five decimal places.
.....
var = 1.999999
debug.print Format(var, "#.00000")

Returns 2
....
I need it to return 1.99999"
 
Upvote 0
Misread the question, sorry, Rick.
 
Upvote 0
As my Excel uses comma as decimal separator this worked for me
Debug.Print Mid(var, 1, InStr(1, var, ",") + 5)

So i think this should work for who uses dot as decimal separator
Debug.Print Mid(var, 1, InStr(1, var, ".") + 5)

M.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top