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?

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?

ASKER

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.

ASKER

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.......

If Right (Myvariable,1) <> 0 then.......

ASKER CERTIFIED SOLUTION

membership

This solution is only available to members.

To access this solution, you must be a member of Experts Exchange.

ASKER

Love it!

Great!

/gustav

/gustav

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