js the number of effects rounded to two, js Number will be converted to the character type

Today, when writing code in a spot of problems, specifically write down, so as not to forget!
Rounding method:

. 1  // NUM for incoming, n for decimal reserved 
2  function fomatFloat (NUM, n) {   
 . 3      var F = parseFloat (NUM);
 . 4      IF (isNaN (F)) {
 . 5          return  to false ;
 . 6      }   
 . 7      Math.round = F (NUM * Math.pow (10, n-)) / Math.pow (10, n-); // n-power    
. 8      var S = f.toString ();
 . 9      var s.indexOf RS = ( ' . ' );
 10      // determines if it is an integer, decimal increased supplemented 0 
. 11      IF (RS <0 ) {
 12 is          RS = s.length;
 13 is          S = +' '.; 
14     }
15     while(s.length <= rs + n){
16         s += '0';
17     }
18     return s;
19 }

 

Do simple addition and subtraction, multiplication and division four operations in the js file, be sure to pay attention to: first convert to Number type character type, when the last output value in the conversion into a character type (call is toString () method), if you do not to do so, it is being given the.

. 1     var tAmnt AmntCurrencyGrid.getRowColData = (I, 2); // liability original insured 
2      var tPrem AmntCurrencyGrid.getRowColData = (I,. 3); // liability original premium 
. 3      var tChangeAmnt AmntCurrencyGrid.getRowColData = (I,. 4); // the responsibility adjusted insured 
. 4      var = Number the tChangePrem (tPrem) * Number the (tChangeAmnt) / Number the (tAmnt);
 . 5      tChangePrem = fomatFloat (tChangePrem, 2 );
 . 6      AmntCurrencyGrid.setRowColData (I,. 5, tChangePrem.toString () );

 

Guess you like

Origin www.cnblogs.com/dongyaotou/p/11758816.html