I have some integer values like 1447948,21163176,95999 and I wanna make them like that:
- 1447948--> 1400000
- 21163176-->21000000
- 95999-->95000
How can I make this with using java?
I have some integer values like 1447948,21163176,95999 and I wanna make them like that:
How can I make this with using java?
On
You can do it for any number by treating it as a string:
int number = 1447948;
String number1 = String.valueOf(number);
String[] split = number1.split("");
StringBuilder number2 = new StringBuilder();
for (int i = 0; i < split.length; i++) {
if(i > 1)
number2.append("0");
else
number2.append(split[i]);
}
int result = Integer.parseInt(number2.toString());
System.out.println(result);
Because rounding is something that is count from the right, you cannot use it, you can just pass from string and use a basic regex to replace the non-2 first digits by
0:(?<=\\d{2})\\dmatch the digits that have two digits before themWorkable Demo