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>