• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use ceil() method for a bigdecimal type value in java?

 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi.. what i want, the field in the entity and model class are of bigdecimal types:-
i want to do some calcultion in bigdecimal and finally store the value after using the Math.ceil() method.

iam not able to covert or type the bigdecimal into some double values first and then trying to store into database.

for e.g;-

bigdecimal requesteQty;

requestedQty = < some value calculated in bigdecimal>

and then trying to store it in Math.ceil(requestedQty )

it gives the following error :-
"This method Math.ceil(dobule) is not applicable for the bigdecimal value.

please help me..
thank you
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Math.ceil takes a double, not a BigDecimal. If you want to get the ceiling of a BigDecimal round it up with a scale of 0:
 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
iam sorry buddy, but i think still iam not getting the correct result.
for e.g-

if i divide 12 by 10, iam getting 1(means 1.2), i want the next higher integer value i.e. - 2


finalRequestedQty is giving me 1 which is incorrct according to CEIL()

thank you
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem must be in the "NumberUtil.divideBigDecimal()" routine, or the "irDetail.getSentToPrQty()" or "part.getUomConversion()" methods aren't returning what you think they are. The solution you've been given is correct; running the following code gives "2" as the final answer:


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic