Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Scientific Notation to standard decimal

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 05-25-2012, 12:40 AM PM User | #1 Aboxofdonuts New to the CF scene   Join Date: May 2012 Posts: 6 Thanks: 4 Thanked 0 Times in 0 Posts Scientific Notation to standard decimal I'm using java to convert a number that was input by the user in a text box. The user then selects the conversion to do, and then it outputs the converted number to another text box. However, the conversion equations use scientific notation. I want to make another text box that takes the result in scientific notation and turns it into standard decimal format. example: x=1 equation is x*1e-6 first result text box would read 1e-6 second result text box would read 1000000 I've never had to do something like this before, so I'm clueless as to where to even begin. Google proved kinda useless. Couple of ideas but I didn't understand them or couldn't get them to work. Any ideas? Not sure if this will be simple or not lol. Thanks in advanced
 05-25-2012, 12:58 AM PM User | #2 xelawho Senior Coder     Join Date: Nov 2010 Posts: 2,591 Thanks: 54 Thanked 477 Times in 475 Posts mmm... but doesn't 1e-6 equal 0.000001? javascript has built-in methods for converting to and from exponential numbers: https://developer.mozilla.org/en/Jav...Objects/Number so you can do something like this: Code: ``` ```
05-25-2012, 01:42 AM   PM User | #3
Aboxofdonuts
New to the CF scene

Join Date: May 2012
Posts: 6
Thanks: 4
Thanked 0 Times in 0 Posts
Quote:
 Originally Posted by xelawho mmm... but doesn't 1e-6 equal 0.000001?
My bad, in the original post I did 1e6 instead of 1e-6.

I was trying the code you used in a brand new dreamweaver file, and if you change the text box to 1e-7 the second text box comes out as scientific notation. Is there a limit to what it can convert? 1e7 works, 1e20 works, but it seems negatives don't.

Some of the equations are like this: 2.47105381e-16 . So I'd hate to have negative numbers not work.

Edit: Just tested my project again, and it seems to automatically convert to decimal when it does the math, however, it only works till a certain amount like stated above.

Now, I'm just scratching my head on this lol.

 05-25-2012, 02:47 AM PM User | #4 Old Pedant Supreme Master coder!     Join Date: Feb 2009 Posts: 24,965 Thanks: 75 Thanked 4,309 Times in 4,276 Posts No, toPrecision() does *NOT* force scientific notation, at all. Dunno why Xelawho gave you that answer. Actually, if you use toPrecision() [no argument] it is no different than toString(). Only if you give it an argument will it be different. But it still won't FORCE scientific notation. You want toExponential(digits) Example: Code: `````` __________________ An optimist sees the glass as half full. A pessimist sees the glass as half empty. A realist drinks it no matter how much there is.
05-25-2012, 09:45 AM   PM User | #5
Philip M
Supreme Master coder!

Join Date: Jun 2002
Location: London, England
Posts: 17,494
Thanks: 200
Thanked 2,471 Times in 2,449 Posts
Quote:
 I'm using java to convert a number
This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia!

You convert a positive or negative scientific format number to standard decimal simply with *1. But 2.47105381e-16 is too big a number for Javascript to handle.

Code:
```<input type = "text" id = "txt1" value = 1e06>
<input type = "text" id = "txt2">
<input type = button value = "Click" onclick = "makeNumber()">

<script type="text/javascript">

function makeNumber() {
var x = document.getElementById("txt1").value;
document.getElementById("txt2").value = x*1;

}
</script>```
Further examples to study:-
Code:
```<script type="text/javascript">

alert (Math.pow(10,21));  // Javascript can display numbers up to 10 ^ 20, thereafter in scientific/exponential notation.

// You can use toFixed() instead of parseFloat() to format positive numbers the way you want up to 20 places of decimals.
// For example (1.23e-7).toFixed(9) will render as 0.000000123

alert (2.47105381e-16.toFixed(20));  // returns positive value
alert ((-2.47105381e-16).toFixed(20));  // using parentheses returns negative value
alert (2.47105381e-16.toFixed(21));  // out of range

// Using .toFixed() with negative numbers requires the value to be placed in parentheses as, due to operator precedence, negative numbers don't return a string.

</script>```
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 05-25-2012 at 12:02 PM..

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 06:58 PM.