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








Reply via email to