Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rounding a double value to n decimal places

Status
Not open for further replies.

p3aul

Instructor
Jul 17, 2004
16
0
0
US
I have a variable of type double that I want to display in an edit box. after I do my calculations I am left with a number that has about 10 decimal places and I want to reduce it to 3 decimal places. How Do I do this?
TIA,
Paul

The Bad News: Time Flies
The Good News: You are the Pilot
 
Use the [blue]FormatFloat[/blue] function.
Usage : [green]FormatFloat('#,##0.00', myValue)[/green]

From the help files: "The number being formatted is always rounded to as many decimal places as there are digit placeholders ('0' or '#') to the right of the decimal point."

Anywhere you place a Zero, it will always display at least a zero there. Anywhere you place a (number / pound) sign will be filled if a value is there.
The usage showed above will show tousands, separated by comma (or millions, or more, all with commas for every 3 places) if the value is that large. Also above, will always display 2 places after the decimal. Just add another zero and you are rounding to 3 decimal places.

In the help files there is a lot more on this function.
Hope this helps.

~
Don't take life too seriously, its not permanent anyways.
 
Thanks, Opieo, I slept on it and decided to change my edits to mask edits and that solved my problem!
Paul

The Bad News: Time Flies
The Good News: You are the Pilot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top