I don't need a round-off value ,help me out... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I don't need a round-off value ,help me out...

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); /*Amountip = 1,00,000*/ int month1 = amount /10; int balanceAm = amount-month1; int month2 = balanceAm/10; balanceAm = balanceAm-month2; int month3 = balanceAm/10; balanceAm = balanceAm-month3; int month4 = balanceAm/10; balanceAm = balanceAm-month4; int month5 = balanceAm/10; balanceAm = balanceAm-month5; float month6 = balanceAm/10; float x = month6 ; int value = (Math.round(x)); int finalAm = balanceAm-value; System.out.println(finalAm); // find the closest int for the double } } Expected out : 53144 But I got this output : 53145

31st Dec 2020, 2:36 PM
Pradeep kumar V
Pradeep kumar V - avatar
3 Answers
+ 3
Alphin K Sajan Ohh.. didn't notice. 😀😀
31st Dec 2020, 5:43 PM
A͢J
A͢J - avatar
+ 1
Pradeep kumar V Use ceil instead of round and take amout in double. Finally cast double to int to get actual result. One more thing don't write hard code logic even you can use loop to get final amount.
31st Dec 2020, 4:21 PM
A͢J
A͢J - avatar
+ 1
I Am Groot ! No prob sir , happens 😂
31st Dec 2020, 5:48 PM
Alphin K Sajan
Alphin K Sajan - avatar