Hi,
I have a calculator with seven textBox to add Float numbers upto 2 decimal:
I have created following function in js:
When I enter following data in fields
2.00
3.00
6.00
------
11.00 <----as expected
But when I enter float value I get
2.22
3.33
--------
5.5500000000000 01 <---- not expected
5.55 is expected
Second thing is after unloading of this page all the field values should be stored in Cookied and when again come on this calculator page value gets loaded from cookie.... [Remeber Browser is still not closed].
But when closed all the cookies should be deleted..
Please help me on this..
Regards,
I have a calculator with seven textBox to add Float numbers upto 2 decimal:
I have created following function in js:
Code:
function total_expenses() {
// reteriving all the values from textboxes and parsing string to Float
var txtBx1 = parseFloat(document.getElementById('textField01').value);
var txtBx2 = parseFloat(document.getElementById('textField02').value);
var txtBx3 = parseFloat(document.getElementById('textField03').value);
var txtBx4 = parseFloat(document.getElementById('textField04').value);
var txtBx5 = parseFloat(document.getElementById('textField05').value);
var txtBx6 = parseFloat(document.getElementById('textField06').value);
var txtBx7 = parseFloat(document.getElementById('textField07').value);
// Storing total
var totalVal = txtBx1 + txtBx2 + txtBx3 + txtBx4 + txtBx5 + txtBx6 + txtBx7;
// converting numeric to string
var strttl = totalVal + "";
// Reformatting the total value
document.getElementById('textField08').value = ReFrtFld(strttl);
estimated_tax_savings();
}
//reformat to 0.00 format
function ReFrtFld(mystring) {
var num;
// using regular expression checking for numeric value upto two decimals.
if (mystring.match(/^\d+$|^\d+\.\d{1}$/)) {
num = parseFloat(mystring).toFixed(2);
return num;
} else {
return mystring;
}
}
When I enter following data in fields
2.00
3.00
6.00
------
11.00 <----as expected
But when I enter float value I get
2.22
3.33
--------
5.5500000000000 01 <---- not expected
5.55 is expected
Second thing is after unloading of this page all the field values should be stored in Cookied and when again come on this calculator page value gets loaded from cookie.... [Remeber Browser is still not closed].
But when closed all the cookies should be deleted..
Please help me on this..
Regards,
Comment