Jump to content
php.lv forumi
  • 0

math.round gļuko


anonīms

Question

Recommended Posts

  • 0
(basket_money + delivery).toFixed is not a function

[break On This Error] basket_money = (basket_money+delivery).toFixed(2);

 

    basket_money = (basket_money+delivery).toFixed(2); 
   //alert(basket_money);
   $('#cart_item_price_total').html('Ls '+basket_money);

 

;/

Link to comment
Share on other sites

  • 0

briedi, tavam tas pats errors.

    var basket_money = $('#cart_item_price_total').html();
   basket_money = basket_money.substr(3);
   basket_money = Math.round((basket_money + delivery) * 100) / 100;
   $('#cart_item_price_total').html('Ls ' + basket_money);

 

Izvada "Ls NaN"

 

substr tiek lietotots, jo tiek aizvākts "Ls " pirms tiek aprēķināts

Link to comment
Share on other sites

  • 0

gļukains tas float

0.71 + 3.90 = 4.609999999999999

(0.71 + 3.90) * 100 / 100 = 4.609999999999999

0.07 + 0.08 = 0.15000000000000002

function addNumbers() {
   for (var c=0,i=0,l=arguments.length;i<l;++i) {
     if (!isNaN(arguments[i])) { c += Math.round(arguments[i] * 100); }
   }
   return c / 100;
}

addNumbers(0.71, 3.90); //4.61

addNumbers(0.07,0.08); // 0.15

Edited by indoom
Link to comment
Share on other sites

  • 0

indoom, kāpēc jāsarežģī?

 

basket_money = Math.round((basket_money+delivery)*100)/100;
alert(basket_money);

 

 

Edit:

var original=28.453

1) //round "original" to two decimals
var result=Math.round(original*100)/100  //returns 28.45

2) // round "original" to 1 decimal
var result=Math.round(original*10)/10  //returns 28.5

3) //round 8.111111 to 3 decimals
var result=Math.round(8.111111*1000)/1000  //returns 8.111

Edited by Toms
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...