Actually, that will have problems too.

v = 1.5436;
var vString:String = String(Math.round(v*100));
var vLength:int = vString.length;
vString = vString.substr(0,vLength-2) + "." + vString.substr(sLength-2);

Go with the number formatter.

-TH

--- In [email protected], "Tim Hoff" <timh...@...> wrote:
>
>
> v = (Math.round (v*100))/100;
>
> -TH
>
> --- In [email protected], Marco Catunda marco.catunda@
> wrote:
> >
> > I resolved the problem of Floating Point.
> > I hadn't find any round function at Flex library. But this is on
> > NumberFormatter class.
> > Sorry!!
> >
> > Here is a workaround of this issue.
> >
> > <?xml version="1.0" encoding="utf-8"?>
> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> layout="absolute"
> > creationComplete="onCreationComplete(event)">
> >
> > <mx:Script>
> > <![CDATA[
> > import mx.formatters.NumberFormatter;
> > import mx.events.FlexEvent;
> >
> > public function onCreationComplete(event:FlexEvent):void{
> > var v:Number;
> >
> > v = 540.54;
> > v += 1192.32;
> > v += 1192.33;
> >
> > var f:NumberFormatter = new NumberFormatter();
> > f.rounding = "nearest";
> > f.precision = 2;
> >
> > textInput.text = f.format(v.toString());
> > }
> >
> > ]]>
> > </mx:Script>
> >
> > <mx:TextInput id="textInput" verticalCenter="0"
horizontalCenter="0"/>
> >
> > </mx:Application>
> >
> > --
> > Marco Catunda
> >
> >
> >
> >
> > On Mon, May 4, 2009 at 8:55 PM, Marco Catunda marco.catunda@ wrote:
> > > I've just stumble upon this problem... Take a look at below code:
> > >
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> layout="absolute"
> > > creationComplete="onCreationComplete(event)">
> > >
> > > <mx:Script>
> > > <![CDATA[
> > > import mx.events.FlexEvent;
> > >
> > > public function
> onCreationComplete(event:FlexEvent):void{
> > > var v:Number;
> > >
> > > v = 540.54;
> > > v += 1192.32;
> > > v += 1192.33;
> > >
> > > textInput.text = v.toString();
> > > }
> > >
> > > ]]>
> > > </mx:Script>
> > >
> > > <mx:TextInput id="textInput" verticalCenter="0"
> horizontalCenter="0"/>
> > >
> > > </mx:Application>
> > >
> > >
> > > The result should be 2925.19, but I've got 2925.1899999999996.
> > >
> > > Any tips?
> > >
> > >
> > > Cheers
> > > --
> > > Marco Catunda
> > >
> >
>



Reply via email to