All-
I have an app in which the users inputs data such as the cost of a dinner bill and the tip percentage and the number of people. The app than takes the numbers and outputs the total bill cost and the amount each person has to pay. I am almost there but when the user inputs numbers that don’t work well I get outputs like $23.576 or $34.999999999. My question is how do I make the app round the two output answers to two decimal places ($55.349 goes to $55.35)?
Thanks in advance!
All- I have an app in which the users inputs data such as the
Share
You can use
Math.roundlike so:Keep in mind, however: you should NOT use double when it comes to financial applications. Since yours appears to be small-scale, you should be fine, however,
BigDecimalis much easier to use for purposes like these.How to use BigDecimal: clicky.