Title: Message
Java offers BigInteger and BigDecimal. It might make sense to avoid doing business logic on the client and let the server handle the arbitrary-precision decimal arithmetic. You could send data back and forth as strings.
 
- Gordon
-----Original Message-----
From: Gordon Smith [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 03, 2005 9:48 AM
To: '[email protected]'
Subject: RE: [flexcoders] Number Format issue. I need help.

Hi, Valy.
 
There is nothing strange going on here. You would have exactly the same problem using "double" in C++.
 
A Number in the Flash Player uses the double-precision IEEE 754 standard representation for a binary floating-point value. (Why? Because this is the representation manipulated at the machine-code level in today's microprocessors.) It uses 64 bits, 52 of which store the binary digits, 11 store the exponent, and 1 stores the sign. 52 binary digits can store only 15-16 decimal digits. (Solving 10^n = 2^52 gives n = 15.65).
 
Furthermore even a decimal number with only a few significant digits, such as 1.3, can't be exactly stored as a Number. It might get stored as something like 1.29999999999999 or 1.30000000000001 because many decimal fractions can't be exactly represented by any finite number of binary digits, and vice versa.
 
If your application requires arbitrary-precision decimal arithmetic rather than fixed-precision binary arithmetic, you will need to find or write a package that does this. Flex doesn't offer such a package at this time, but perhaps others on this list know of such a package written in ActionScript.
 
- Gordon
-----Original Message-----
From: Valy Sivec [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 03, 2005 8:25 AM
To: [email protected]
Subject: RE: [flexcoders] Number Format issue. I need help.

Hi Abdul,
 
I'm working for a financial application and this behaviour in my opinion is unaccceptable...I'm hesitant to believe that our QA eng, not mentioning the clients will accept this....
 
Can't believe that such a basic thing  cause me so much trouble... is there anybody in on this forum that used math operations with large number in double precision and avoided this issue?
 
Any help, suggestions would be greatly appreciated.
 
Thanks,
Valy
 


Abdul Qabiz <[EMAIL PROTECTED]> wrote:
Hi Valy,
 
Thats how Flash Player rounds off the numbers automatically, if you have a number like this:
 
var s2 = 12345678901234.95; //it would show as 12345678901234.9
 
and
 
var s2 = 12345678901234.96; //it would show as 12345678901235
 
 
Not sure, how to solve this....Someone who has done it earlier, might want to comment...
 
-abdul
 
 
 
 


From: Valy Sivec [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 03, 2005 9:18 PM
To: [email protected]
Subject: RE: [flexcoders] Number Format issue. I need help.

Abdul,

thanks for your example it was very helpfull.... I added an extra text box and wanted to do some sum between the 2 boxes... very basic stuff...

function setOutput()

{

var value1 : Number = parseFloat(in_ti.text);

var value2 : Number = parseFloat( in_ti2.text ) ;

var total : Number;

total = value1 + value2;

out_ti.text = getDecimalString(total);

// out_ti.text = numberformatter.format( getDecimalString(total) );

}

 

Well when I add 0.9990000344032 with 12345678901234.00000000000001 the result is: 12345678901235 ( no decimals )

or

0.9990000344032

+ 11111111111.00000000000001 = 11111111111.999 ( only the first 3... ) I would like to see all the decimals...

 

Can you help me? Am I missing something? Below you can find the modified code.

Thanks,

Valy

<code>

<?xml version="1.0" encoding="utf-8"?>

<mx:Application width="800" height="600"

xmlns:mx="http://www.macromedia.com/2003/mxml">

<mx:Script>

<![CDATA[

function getDecimalString(n:Number):String

{

var s:String = n.toString();

if(n.toString().indexOf("e-")!=-1 ) {

var arr = n.toString().split("e-");

var v1 = Number(arr[0]);

var v2 = Number(arr[1]);

s = "0.";

var i = 0;

while(i++<v2) s+="0";

var s1 = v1.toString();

s+= s1.length>1 ? s1.split(".").join("") : s1;

}

return s;

}

function setOutput()

{

var value1 : Number = parseFloat(in_ti.text);

var value2 : Number = parseFloat( in_ti2.text ) ;

var total : Number;

total = value1 + value2;

out_ti.text = getDecimalString(total);

// out_ti.text = numberformatter.format( getDecimalString(total) );

}

]]>

</mx:Script>

<mx:Style>

Label {

font-size:14;

color:white;

}

</mx:Style>

<mx:VBox horizontalAlign="left">

<mx:HBox>

<mx:Label text="Input:"/>

<mx:TextInput id="in_ti" text="0.0000000000000000009990000344032" width="300" />

<mx:TextInput id="in_ti2" width="300" />

<mx:Button id="convert_btn" label="Convert" click="setOutput();"/>

</mx:HBox>

<mx:HBox>

<mx:Label text="Output:"/>

<mx:TextInput id="out_ti" text="" width="300"/>

</mx:HBox>

</mx:VBox>

<mx:NumberFormatter id="numberformatter" precision="20" useThousandsSeparator="true" useNegativeSign="true"/>

</mx:Application>

 

 



Abdul Qabiz <[EMAIL PROTECTED]> wrote:
Show it as string, I mean internally calculate as number then convert number
to string and show in the textfield....

I wrote a quick & dirty routine, that might help you.....There might be a
better way to do, this is what I have done using string operations...




<code>

function getDecimalString(n:Number):String
{
     
      var s:String = n.toString();
     
      if(n.toString().indexOf("e-")!=-1) {
            var arr = n.toString().split("e-");
            var v1 = Number(arr[0]);
            var v2 = Number(arr[1]);
            s = "0.";
            var i = 0;
            while(i++<v2) s+="0";
            var s1 = v1.toString();
           
            s+= s1.length>1 ? s1.split(".").join("") : s1;
      }

      return s;
     
}

</code>




An example:


####DecimalToString.mxml####

<?xml version="1.0" encoding="iso-8859-1"?>
<mx:Application width="800" height="600"
xmlns:mx="http://www.macromedia.com/2003/mxml">

    <mx:Script>
        <![CDATA[

      

        function getDecimalString(n:Number):String
        {
             
              var s:String = n.toString();
             
              if(n.toString().indexOf("e-")!=-1) {
                    var arr = n.toString().split("e-");
                    var v1 = Number(arr[0]);
                    var v2 = Number(arr[1]);
                    s = "0.";
                    var i = 0;
                    while(i++<v2) s+="0";
                    var s1 = v1.toString();
                   
                    s+= s1.length>1 ? s1.split(".").join("") : s1;
              }
       
              return s;
             
        }
       
        function setOutput()
        {
            out_ti.text = getDecimalString(parseFloat(in_ti.text));
        }




        ]]>
    </mx:Script>
    <mx:Style>
   
        Label {
       
                font-size:14;
                color:white;
               }
       
    </mx:Style>
    <mx:VBox horizontalAlign="left">
        <mx:HBox>
            <mx:Label text="Input:"/>
           <mx:TextInput id="in_ti" text="0.0000000000000000009990000344032"
width="300" />
           <mx:Button id="convert_btn" label="Convert"
click="setOutput();"/>
        </mx:HBox>
       
        
        <mx:HBox>
            <mx:Label text="Output:"/>
            <mx:TextInput id="out_ti" text=""/>
        </mx:HBox>
   </mx:VBox>
</mx:Application>


-abdul



-----Original Message-----
From: Valy Sivec [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 03, 2005 8:54 AM
To: [email protected]
Subject: Re: [flexcoders] Number Format issue. I need help.


I spent some time without figuring out a way to format a number in double
precision.

I have a grid and below it a total field that should sum the grid colums.
When I enter in the grid columns values as 0.00000008, 0.00000001 the result
field displays 9e-8, which is correct but I would like to display it as
0.00000009 instead.... Any suggestions?

Thanks,
Valy


--- Valy Sivec <[EMAIL PROTECTED]> wrote:

> Hello,
>
> I have some some number formatted form elements that I need to sum up.
> In order to do that, I use parseFloat to extract the number out of the
> formatted string input. When the number has more than 5 decimals,
> let's say "0.0000008", the get back the trailing
> exponents:
> 8e-7.
>
> Is there a way to get back the number without the trailing exponents
> (0.0000008)?
>
>
> TIA,
> Val.
>
>
>
>
>      
>            
> __________________________________
> Celebrate Yahoo!'s 10th Birthday!
> Yahoo! Netrospective: 100 Moments of the Web
> http://birthday.yahoo.com/netrospective/
>



     
           
__________________________________
Celebrate Yahoo!'s 10th Birthday!
Yahoo! Netrospective: 100 Moments of the Web
http://birthday.yahoo.com/netrospective/



Yahoo! Groups Links








Celebrate Yahoo!'s 10th Birthday!
Yahoo! Netrospective: 100 Moments of the Web


Celebrate Yahoo!'s 10th Birthday!
Yahoo! Netrospective: 100 Moments of the Web

Reply via email to