Link to home
Start Free TrialLog in
Avatar of thandel

asked on

Formatting decimals and whole numbers

I have a text box on a form that displays some calculation based on the form.  All is working well but sometimes I have to display a decimal and other times a whole number.  This number represents month(s) so if the value is whole I don't want to display a decimal and when its not whole I want to display to one tenth of the value.

i.e. 12 months vs. 0.5 months.

I'm using Format (MyVariable, "0.0") which works OK but then the decimal is always displayed.

Any ideas?
Avatar of andygrant2005
Flag of United Kingdom of Great Britain and Northern Ireland image

You could try rounding the number instead :

Round( MyVariable, 0 )

This will always give whole numbers rather than the decimal places.

Or you can use :

Fix( MyVariable )

to fix the number and loose the decimal place completely, so 9.6 would give 9
Avatar of thandel


I need to keep the decimal when its less than 1.0 (i.e. .5 or .7)  I think your solutions will always remove the decimal.
Avatar of thandel


I'm thinking that I need to first determine if the number is whole or not.  Is there any better way then simply

If Right (Myvariable,1) <> 0 then.......
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thandel


Love it!