1, the decimal point clear 0:
Copy Code code as follows:
function ReturnFloat0 (value) {
Value = Math.Round (parsefloat (value));
return value;
}
2. Keep a decimal point:
Copy Code code as follows:
function ReturnFloat1 (value) {
Value = Math.Round (parsefloat (value) * 10)/10;
if (value.tostring (). IndexOf (".") < 0) {
Value = value.tostring () + ". 0";
}
return value;
}
3. Keep two decimal points
Copy Code code as follows:
function ReturnFloat2 (value) {
Value = Math.Round (parsefloat (value) * 100)/100;
if (value.tostring (). IndexOf (".") < 0) {
Value = value.tostring () + ". 00";
}
return value;
}
4, keep two decimal points, a decimal automatically fill 0
Copy Code code as follows:
function ReturnFloat3 (value) {
value = Math.Round ( parsefloat (value) * 100)/100;
var xsd = value.tostring (). Split (".");
//ext.log (xsd.length);
if (xsd.length==1) {
value = value.tostring () + " .00 ";
return value;
}
if (xsd.length>1) {
if (xsd[1].length<2) {
value = value.tostring () + "0";
}
return value;
}
}