Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do not supress leading and ending zeroes

Status
Not open for further replies.

khue

Programmer
Mar 6, 2001
112
US
I have a fixed length float number for example 99999.99 where 9 is a number from 0 - 9. I want to display all the digit position regardless if it has leading zeroes or ending zeroes.

For example:

function nameX()
{
var x = 00083.10

document.form[0].text1.value = var
}

when displayed, I want to see exactly 00083.10 and not
83.1

How do I tell JavaScript to display leading and ending zeroes?
 
it has to be a string. you can't format numbers like that unless its a string object.

this will work:

var x = "00009.8900";

or you could make it a string by:

var x = new String("008.985200"); luciddream@subdimension.com
 
jared,
document.form[0].text1.value = new String(x)

won't work, because it's already turned it into a number and cut off leading and trailing 0's luciddream@subdimension.com
 
It's an example I'm giving. What if the value of x is a result of a math calculation or a value passed from another program. I still want to maintian all the digit positions including leading and ending zeroes.
 
make it a string when its passed.

var x = new String(obj.getResult());

that should maintain the formatting. luciddream@subdimension.com
 
all,

oops, yeah, my solution didn't work ;-)

lucid,

that probably won't work either, as by the time it is returned, even from another program (such as an ActiveX control) it is turned into a javascript numeric primitive.

khue,
you'll just need a formatting function that takes it and turns it into a string and applies the formatting you desire jaredn@eae.net -
 
you have to add with another string like '0000000000' and get right side sub string
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top