1

I am trying to convert a Minimum Bounding Rectangle from double values to float values. After the conversion, I need the (float) rectangle to be equal to or contain the (double) rectangle (the float rectangle needs to be bigger than or equal to the double rectangle). To do that I want to be able to specify which way to round the double to convert it to float. So, when casting the "Top" of the rectangle, I would round up, but when casting the "Bottom" of the rectangle, I would round down.

Is there a class that allows me to do this?

Thanks.

asked May 15, 2011 at 18:21

2 Answers 2

1
Math.ceil( double ); - round up
Math.round( double ); - round down
answered May 15, 2011 at 18:27
Sign up to request clarification or add additional context in comments.

Comments

0

You can compare the float to the double and if it needs to be slightly larger or smaller you can call floatToIntBits and intToFloatBits with an increment or decrement as required.

answered May 15, 2011 at 18:49

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.