This is probably such a simple answer… I’ve searched the web and can’t find the answer!!! Someone said use ‘math.round’ but I haven’t gotten that to work. How in the world do you round a number, whether it’s up, down, or to two decimal spots? Please help and thanks to whoever does!
Can anyone help me with this?
what is your situation ? what code are you using ? what do you want in results ?
Thanks for responding Shan! I’m building a site where customers can select different components and the price adjusts based on what they are choosing. I also have a discount section that subtracts percentages from the total price. However, instead of a price like “$9.53” showing, it’ll be “$9.5394398479389” or something equally ridiculous.
Here’s an example of the code I’m using for the discounts:
$w(“#militarydisc”).value = (+$w(“#militarycheck”).value) * 0.05 * (+$w(“#totalyearprice”).value);
Where “military disc” displays the actual dollar amount of the discount.
“military check” is a yes/no radio button with yes as a value of 1, and no a value of 0.
“total year price” is the price of the product.
So this is how I do a 5% military discount. 5% doesn’t really cause any problems but odd numbers like 3.5% typically give me repeating numbers. I want to either round up/down to the nearest whole dollar amount AND also learn how to round to a certain decimal point. (1 or 2 places, ex: $9, $9.5 & $9.53)
Thanks!
I think i understand a little bit of what you are saying.
I needed to get my decimal points to 2 decimal places so I did this:
const originalPrice = $w("#gt").text;
let newPrice = (Number(originalPrice)) - ((Number(originalPrice/100)) * (Number($w('#discount').value)));
await $w("#discountbox").show();
$w('#gt').text = parseFloat(String(newPrice)).toFixed(2); //this is what you want
math.round should give you the nearest whole number. same concept as above
Hope it helps!
I will give it a shot. Thank you sir!
Quick question, in that example, where would you put math.round?
in place of parseFloat
while removing the .toFixed