aspose 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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 19538
    
  16

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: 24166
    
  30

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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to use ceil() method for a bigdecimal type value in java?
 
Similar Threads
BigDecimal
Using BigDecimal in ActionForm
Case Study On Sales Tax Problem
How to avoid rounding while BigDecimal division
BigDecimal divide question