+ 2

I don't know exactly if it's my error or if there is something else.

I was trying many things in an "easy exercise" Kaleidoscopes shop: 1- scan N input and multiply * 5.00 2- if N > 1 subtract 10% 3- add tax 7% 4- show result with 2 decimal maximum When it comes to money 💵 i used the bigdecimal class of java.math with RoundingMode.HALF_EVEN For some reason when N = 15, In the tests the result is 14.45 I can't make sense of that because I did a lot of loss of precision tests with the numbers and the only way for that result is to round up. But in the other cases in none it is necessary to round up but give the exact approximation of the decimals, which is achieved with bigdecimal I had to make a condition only for 1 case and would like to have and have if it is a mistake on my part. Here below my solution https://code.sololearn.com/c3u9MyeAvejE/?ref=app Thanks for taking the time.

21st Aug 2020, 12:46 PM
Johnkegd
Johnkegd - avatar
3 Antworten
+ 1
I tried to calculate the example you gave N=15 and the result was 14.45. As far as I can see, the calculation was ok. Take 10% off from 15. Than add 7% and you get 14.445. If you a re using two decimal maximum, you will get 14.45 Your calculation was well, with high-precision.
21st Aug 2020, 8:02 PM
Balthasar-Max. Althaus
Balthasar-Max. Althaus - avatar
+ 3
Thanks Max😅👍 i hope
21st Aug 2020, 8:09 PM
Johnkegd
Johnkegd - avatar
+ 2
That's not exactly my question, I just want to know if I'm calculating well, with high-precision arithmetic or I'm losing precision at the moment to print with format.
21st Aug 2020, 1:29 PM
Johnkegd
Johnkegd - avatar