简体   繁体   English

如何使用jQuery在输入中的浮点值中的点后隐藏数字

[英]How to hide numbers after dot in float value in input using jquery

I am developing a financial calculator and i am facing a problem to get exact answers if i round the value . 我正在开发一个金融计算器,如果我将价值四舍五入,我将面临一个难题,无法获得确切答案。 Basically i dont want to show numbers after dot in float value, but i need the same float value in my calculations. 基本上我不想在浮点值中的点后显示数字,但是我在计算中需要相同的浮点值。 Note :- There are too many calculations so it is tough to save values in variables 注意:-计算太多,因此很难将值保存在变量中

for example 例如

value1 = Math.round(34.55); // it will be 35
$('#input1').val(value1); // and it is fine to show round value which is 35
value2 = ("#input1").val(); // In this line it will be 35 but i need 34.55

try this 尝试这个

var floatVal = 34.55;
value1 = Math.round(floatVal); // it will be 35 
$('#input1').attr("data-floatVal","34.55");
$('#input1').val(value1);
//it's important to parseFloat
value2 = parseFloat($("#input1).attr("data-floatVal")); 

set it as an attribute of that input element 将其设置为该输入元素的属性

var decimalValue = 34.55;
$('#input1').attr( "data-value", decimalValue );
$('#input1').val( Math.round( decimalValue ) ); 
value2 = ("#input1).val(); //decimal value
actualValue2 = ("#input1).attr( "data-value" ); // float value

try this //I hope this will work for you. 试试这个///我希望这对您有用。 roundValue = Math.round(34.55); roundValue = Math.round(34.55); actualValue=34.55;//Create another variable to store actual value and use when required. actualValue = 34.55; //创建另一个变量以存储实际值并在需要时使用。 $('#input1').val(roundValue); $('#input1')。val(roundValue);

value2 = actualValue; value2 =实际价值;

 try this //I hope this will work for you. roundValue = Math.round(34.55); actualValue=34.55;//Create another variable to store actual value and use when required. $('#input1').val(roundValue); value2 = actualValue; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM