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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NumberFormat() mask length 1

Status
Not open for further replies.

pcorreia

Programmer
Feb 22, 2002
301
US
I'm not very familiar with using NumberFormat() but I have to update some code written by someone else. What I need to do is this: given a decimal value (3.1 or 14.99), format the number to two decimal places. The code used to look like this:
Code:
  #NumberFormat(myVar,"_.__")#
but that started giving us errors when the numbers got bigger than 10. I changed it to this:
Code:
  #NumberFormat(myVar,"__.__")#
which works for now, but I'm looking for a way to make this work always, without having to guess how many digits there may be to the left of the decimal point. For example, in Perl I'd do this:
Code:
  printf("%.2f",$myVar);
and it would just output the number formatted to two decimal places, without me having to worry about how big the number might be.

Any suggestions?
 
Try the DecimalFormat() function:
Code:
#DecimalFormat(MyNum)#
Keep in mind, if there are more than two decimal places, the number will be rounded.

-Tek
 
Thanks, this is exactly what I was looking for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top