improve floating point handling
This commit is contained in:
parent
0537e23e38
commit
06b6054071
@ -14,7 +14,13 @@ $.fn.exponentialInput = function() {
|
||||
var setExponent = function() {
|
||||
var newExponent = parseInt($exponent.val());
|
||||
var delta = currentExponent - newExponent;
|
||||
$input.val(parseFloat($input.val()) * 10 ** delta);
|
||||
if (delta >= 0) {
|
||||
$input.val(parseFloat($input.val()) * 10 ** delta);
|
||||
} else {
|
||||
// should not be necessary to handle this separately, but floating point precision in javascript
|
||||
// does not handle this well otherwise
|
||||
$input.val(parseFloat($input.val()) / 10 ** -delta);
|
||||
}
|
||||
currentExponent = newExponent;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user