@Minamakhlouf
Posted
Hi Adriano,
Very well designed project
The only feedback I would give is to use a function like .toFixed() which would fix the output to 2 decimal spaces, like how a real bill would look.
Example:
let numberBeforeRounding = 3.141413213123123122132;
let numberAfterRounding = numberBeforeRounding.toFixed(2);
numberAfterRounding;
Output: "3.14"
The only problem with this method is that it gives you the value as a string so you'll have to convert that to number data type with Number();
Hope this helps.
Marked as helpful
@AdrianoEscarabote
Posted
@Minamakhlouf
Thank you very much! I had tried using toFixed()
, but I didn't quite understand how it worked! helped a lot
@f-russo
Posted
@AdrianoEscarabote To add to Mina's already good answer, you can prepend +
to a string and it will convert it to a number. It's a shortcut for Number()
.
Example (modified from Mina's comment):
let numberAfterRounding = +numberBeforeRounding.toFixed(2);
Take a look at the Number - Rounding section on Javascript.info for reference.
@AdrianoEscarabote
Posted
@f-russo thanks for the tips man! I already made the change!