views:

141

answers:

2

I have an NSDecimal in a tight calculations loop, where I need to floor the value. I want to prevent creating fat NSDecimalNumber objects just for that. Is there a cost-efficient way to get a floor? That floor is just needed to calculate how many times another value might fit in there, with no rest. The NSDecimal API doesn't provide something like floor...

+2  A: 

You can use the NSDecimalRound() function with the NSRoundDown rounding mode:

NSDecimal d = ...;
NSDecimal floored;

NSDecimalRound(&floored, &d, 0, NSRoundDown);

For more info take a look at the docs here.

Perspx
+1  A: 
NSDecimal result;
NSDecimalRound(&result, &decimal, 0, NSRoundDown);

(not tested)

Wevah