Dan
Dan

Reputation: 2174

get the next highest number value if decimal exists

i am wondering how to get output like 17 if i provide input like 16.001 in java programming?

I tried this (int)Math.ceil(168/10); but it did not worked for me. Please help me. I want 17 output but it was giving 16.

Expected output

String inputval="16.01";
int ouput ;

//output should come as 17

Upvotes: 0

Views: 120

Answers (3)

Sujith Thankachan
Sujith Thankachan

Reputation: 3506

Use this:

String inputval="16.01";
int val = (int) Math.ceil(Double.valueOf(inputval));

Upvotes: 0

Mohammad Ashfaq
Mohammad Ashfaq

Reputation: 1373

double inputval=16.01;
int ouput = ( (int) Math.ceil (inputval) );

//Now output should be 17

Upvotes: 1

Petter
Petter

Reputation: 4165

168/10 will return an integer with value 16. You need to cast one of the integers to a double like this:

(int)Math.ceil((double)168/10);

Upvotes: 3

Related Questions