-2

I'm trying to make a simple script which updates a number based on input field.

Some of the calculations are based on very small numbers, and which makes JavaScript return odd numbers like: 7e-8.

How can I fix this?, I've tried searching google, but haven't found anything useful, like .toFixed(), .toPrecision() and such.

Another problem as well, is how can I limit the returned number to only 8 digits after the dot? Here as well I've tried to do .toFixed(8), but from what I've seen on Google, it's rounding in some cases, which isn't good in my case.

Btw: the number 0.0000007 is pulled from database with PHP, so its not always that number. but its always with 8 digits after the dot.

$("input[name='test']").keyup(function() {
  var value = $(this).val() * 0.0000007;
  $("p").text(value);
}).keyup();
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<input type="text" name="test" value="1">
<p></p>
Convertor
  • 171
  • 1
  • 2
  • 14
  • [This](http://stackoverflow.com/questions/1685680/how-to-avoid-scientific-notation-for-large-numbers-in-javascript) may give you some direction. –  Mar 28 '15 at 23:11
  • I'm sorry, but doesn't help me much, can you clarify a bit more? – Convertor Mar 28 '15 at 23:20

1 Answers1

-1

Found the solution

had to place the .toFixed() the right place

$("input[name='test']").keyup(function() {
  var value = $(this).val() * 0.0000007;
  $("p").text(value.toFixed(8));
}).keyup();
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<input type="text" name="test" value="1">
<p></p>
Convertor
  • 171
  • 1
  • 2
  • 14