Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How does jquery convert 4 decimal places into 1 digit?
How does jquery convert 4 decimal places into 1 digit?
var a = 2. 15 12 13 123 123 132 1; ?

Alert ("two decimal places:" +a.fixed (2)+ "

Others:

? //Keep two decimal places

//Function: Rounds floating-point numbers to 2 decimal places?

Function? toDecimal(x)? {?

var? f? =? parse float(x); ?

What if? (Isnan (f))? {?

Return; ?

}?

f? =? math . round(x * 100)/ 100; ?

Return? f; ?

}?

//The system reserves 2 decimal places, such as 2, which will be supplemented by 00. That's 2.00?

Function? toDecimal2(x)? {?

var? f? =? parse float(x); ?

What if? (Isnan (f))? {?

Return? Fake; ?

}?

var? f? =? math . round(x * 100)/ 100; ?

var? s? =? f . tostring(); ?

var? rs? =? s.indexOf(' . ')); ?

What if? (rs? & lt? 0)? {?

rs? =? S. length; ?

s? +=? '.'; ?

}?

What time? (s.length? & lt=? rs? +? 2)? {?

s? +=? '0'; ?

}?

Return? s; ?

}?

Function? fomatFloat(src,pos){?

Return? math . round(src * math . pow( 10,? pos))/Math.pow( 10,? pos); ?

}?

//circle?

Alert ("Keep 2 decimal places:"? +? toDecimal(3. 14 159267)); ?

Alert ("Forced to keep 2 decimal places:"? +? todecimal 2(3. 14 159267)); ?

Alert ("Keep 2 decimal places:"? +? toDecimal(3. 14559267)); ?

Alert ("Forced to keep 2 decimal places:"? +? todecimal 2(3. 15 159267)); ?

Alert ("Keep 2 decimal places:"? +? fomatFloat(3. 14559267,? 2)); ?

Alert ("Reserved 1 Decimal:"? +? fomatFloat(3. 15 159267,? 1)); ?

//A family of six?

Alert ("Keep 2 decimal places:"? +? 1000.003 . tofixed(2)); ?

Alert ("Reserved 1 Decimal:"? +? 1000.08 . tofixed( 1)); ?

Alert ("Reserved 1 Decimal:"? +? 1000.04 . tofixed( 1)); ?

Alert ("Reserved 1 Decimal:"? +? 1000.05 . tofixed( 1)); ?

//Scientific counting?

alert(3. 14 15 . toexponential(2)); ?

alert(3. 1455 . to exponential(2)); ?

alert(3. 1445 . to exponential(2)); ?

alert(3. 1465 . to exponential(2)); ?

alert(3. 1665 . to exponential( 1)); ?

//accurate to n bits, excluding n bits?

Alert ("accurate to the second decimal place"? +? 3. 14 15 . toprecision(2)); ?

Alert ("accurate to the third decimal place"? +? 3. 1465 . top precision(3)); ?

Alert ("accurate to the second decimal place"? +? 3. 14 15 . toprecision(2)); ?

Alert ("accurate to the second decimal place"? +? 3. 1455 . top precision(2)); ?

Alert ("accurate to the fifth decimal place"? +? 3. 14 1592679287 . to precision(5));