Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

value to the next thousand instead of nearest thousand

Tags:

java

Sorry im new to java, currently i wanted to code the value to next thousand instead of nearest thousand. But i have no ideas how to do it. I tried Math.round but it's for roundest. Please guide me, any help would be appreciated .

Expected output that i looking for :

example 1) if the place values less than 999, it will direct change to 1000

May i know how can i code the math formula for this ?

like image 537
user3835327 Avatar asked Oct 17 '14 09:10

user3835327


2 Answers

You can use Math.ceil for this.

// A quick code example :)
int val = 1400;
val = (int) (Math.ceil(val / 1000.0) * 1000);
like image 186
Jerodev Avatar answered Oct 13 '22 01:10

Jerodev


You need to write some custom code as follow

int leftdigit=value/1000;
int nextthousand=(leftdigit+1)*1000;
like image 34
Hafiz Mujadid Avatar answered Oct 13 '22 00:10

Hafiz Mujadid