Look into using the "Number" object. It has a "toPrecision" method you can use to set the amount of decimal places (see http://msdn.microsoft.com/library/en-us/script56/html/76e87c37-cf6c-46cc-bafa-04be1fe3d78d.asp?frame=true).
Do something like: var myNum = new Number("4.6582612354"); var my2DecNum = myNum.toPrecision(3);
I haven't tested this, so if it doesn't work, get back to me. --- S.Y.M. Wong-A-Ton
"unkown" wrote:
[Quoted Text] > But if i want to get to nearest to 2 decimal places ? > e.g 4.6582612354 -> 4.66 > > Thanks > > "S.Y.M. Wong-A-Ton" wrote: > > > If you're using JScript try using the parseFloat method (see > > http://msdn.microsoft.com/library/en-us/script56/html/a7d87a69-1919-4623-be85-972e6376dd2d.asp?frame=true)> > --- > > S.Y.M. Wong-A-Ton > > > > > > "unkown" wrote: > > > > > Hi, > > > i'm writing a function in infopath which handle some calculation > > > my case as below: > > > 155/3 = 51.6666666 > > > i use the application.formatstring function to extract to nearest 2 decimal > > > places. > > > temp = Application.FormatString(155/3, "number", "numDigits:2") > > > the result of temp is "51.67" > > > but when i use temp to calculate somethings, it will hv error > > > coz the temp is string format, then how can i convert to number format after > > > extract to neatest 2 decimal places ? > > > > > >
|