File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes how to use ceil() method for a bigdecimal type value in java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to use ceil() method for a bigdecimal type value in java?" Watch "how to use ceil() method for a bigdecimal type value in java?" New topic
Author

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

Vinod Vinu
Ranch Hand

Joined: Aug 30, 2009
Posts: 217
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


Vinod Kumar Nair
"Any fool can write code that a computer can understan. Good programmers write code that humans can understand."
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

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:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Vinod Vinu
Ranch Hand

Joined: Aug 30, 2009
Posts: 217
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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:



[Jess in Action][AskingGoodQuestions]
 
GeeCON Prague 2014
 
subject: how to use ceil() method for a bigdecimal type value in java?