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?

Microsoft Access

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.

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

Your help has saved me hundreds of hours of internet surfing.

fblack61

Log in or sign up to see answer

Become an EE member today7-DAY FREE TRIAL

Members can start a 7-Day Free trial then enjoy unlimited access to the platform

or

Learn why we charge membership fees

We get it - no one likes a content blocker. Take one extra minute and find out why we block content.

Not exactly the question you had in mind?

Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.

ask a question
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