Group:  Other Microsoft Office Products ยป microsoft.public.infopath
Thread: format string to number

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

format string to number
unkown 10.07.2006 08:40:02
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 ?


RE: format string to number
S.Y.M. Wong-A-Ton 10.07.2006 18:50:01
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:

[Quoted Text]
> 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 ?
>
>
RE: format string to number
unkown 11.07.2006 01:13:02
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:

[Quoted Text]
> 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 ?
> >
> >
RE: format string to number
S.Y.M. Wong-A-Ton 11.07.2006 17:55:02
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 ?
> > >
> > >

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net