Lightweight way of flooring an NSDecimal?

cocoa-touch, iphone, uikit

Solution

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.

Problem

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...

Original source