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

