i get a float value by this code
currentvalue=$("#double_your_btc_stake").val();
but when i try to write double of the old value
currentvalue*=2;$("#double_your_btc_stake").val(currentvalue);
but it write to input box
2e-8
what i do wrong
i get a float value by this code
currentvalue=$("#double_your_btc_stake").val();
but when i try to write double of the old value
currentvalue*=2;$("#double_your_btc_stake").val(currentvalue);
but it write to input box
2e-8
what i do wrong
JS:-
jQuery(function ($) {
$("#Double").on("click", function () {
var currentvalue = $("#double_your_btc_stake").val();
currentvalue *= 2;
$("#double_your_btc_stake").val(longnumberstring(currentvalue));
});
});
function longnumberstring(n) {
var str, str2 = '',
data = n.toExponential().replace('.', '').split(/e/i);
str = data[0], mag = Number(data[1]);
if (mag >= 0 && str.length > mag) {
mag += 1;
return str.substring(0, mag) + '.' + str.substring(mag);
}
if (mag < 0) {
while (++mag) str2 += '0';
return '0.' + str2 + str;
}
mag = (mag - str.length) + 1;
while (mag > str2.length) {
str2 += '0';
}
return str + str2;
}
HTML:-
<input type="text" id="double_your_btc_stake" style="width:500px" />
<input type="button" id="Double" value="Double" />
Used Reference to convert the exponential to long string.
Simply use this:
parseFloat($("#yourId").val())