It's a common floating point problem. U can solve it by multiplying both values 
with 100 and then ehh / (don't know what the word is) the resulting value by 
100.

var x = ((Number("40") * 100) - (39.90 * 100)) / 100;

trace(x); 


Greetz Erik


-----Original Message-----
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Matt 
Chotin
Sent: woensdag 4 mei 2005 7:55
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Help i don't know

Should Number(tx_inc.text) be parseFloat(tx_inc.text) instead?

-----Original Message-----
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL 
PROTECTED]
Sent: Tuesday, May 03, 2005 9:33 AM
To: Flex Coders
Subject: [flexcoders] Help i don't know

Hi,

if you can see my code, please, "Resto()"  function it's very simple.
If in my tx_inc.text put 40EUR, and in my 
ShoppingCart(mx.core.Application.application.shopping).total put 39.90EUR 
return me 0.10000000000000001???????????
I have trace my var the value for tx_inc.text and for total it's correct, but 
my resto var is crazy? what's i wrong?



<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.macromedia.com/2003/mxml"; height="20%" 
width="100%" visible="true" xmlns="*">
<mx:Script>
<![CDATA[
  import as.*;
  var resto=0;
  public var vendite;
 
  function Resto():Void
  {
   
    if(ShoppingCart(mx.core.Application.application.shopping).total>0 )
    {
      resto=
Number(tx_inc.text)-ShoppingCart(mx.core.Application.application.shopping).t
otal;
      mx.controls.Alert.show(resto);
     
    }
    else
    {
       resto=0;
       tx_inc.text='';
    }
   
   
  }
 
 
  ]]>
</mx:Script>

 <mx:NumberFormatter id="ft_price"
          precision="2"
          rounding="none"
          decimalSeparatorTo=","
          thousandsSeparatorTo="."
          useThousandsSeparator="true"/>
         
<mx:Panel id="tot" title="Totale Scontrino" width="100%" height="100%" 
headerColors="[#FF6600,#FFFFFF]">

<mx:Tile>
<mx:Label id="ltot" text="Totale EUR
{ft_price.format(ShoppingCart(mx.core.Application.application.shopping).tota
l)}" 
fontSize="20"/>
<mx:Label id="lresto" text="Resto EUR {ft_price.format(resto)}" 
fontSize="20"/>
<mx:Label text="Articoli
{ShoppingCart(mx.core.Application.application.shopping).size}" 
fontSize="20"/>
<mx:Label id="lvendite" text="Vendite n°{vendite}" fontSize="20"/> <mx:Label  
text="Incassato" fontSize="20"/> <mx:TextInput id="tx_inc" change="Resto()" 
fontSize="20" /> </mx:Tile> </mx:Panel>

</mx:Canvas>




 
Yahoo! Groups Links



 





 
Yahoo! Groups Links



 





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to