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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert Scientific Notation Number to a readable String

Status
Not open for further replies.

sewl123

Programmer
Mar 4, 2003
1
US
I have the following answer to an equation: 1e-7. I want this to read out as .0000001. I have the same problem with 10000000. I want to convert these numbers to strings. Is there a format function that will stop the answer from appearing in 1e-7 format?
 
how about this?
Code:
Number.prototype.toFullString = function() {
	var isDecimal = /\-/.test(this);
	if (isDecimal) 
		return this.toFixed(this.toString().split("-")[1]);
	else return this;
}

alert(2.34e-6.toFullString());
alert(1e+6.toFullString());

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
No, you'd have to write your own. I'd suggest converting the number to a string ie "1e-7" then using the various slice and dice text functions available to take everything before the 'e', strip the decimal point out, append the right number of zeros either to the left or right and, if necessary, re-append the decimal point.

eg

1.234e-7 = 0.0000001234

1.234e-7, take everything before the 'e'

1.234, strip out the decimal point

1234, append the right number of zeros (7), to the left (-)

00000001234, re-append the decimal point (-)

0.0000001234
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top