Skip to content

Instantly share code, notes, and snippets.

@Morse-Code
Last active August 29, 2015 13:59
Show Gist options
  • Select an option

  • Save Morse-Code/10999079 to your computer and use it in GitHub Desktop.

Select an option

Save Morse-Code/10999079 to your computer and use it in GitHub Desktop.

Revisions

  1. Morse-Code revised this gist Apr 17, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion RoundFloat.m
    Original file line number Diff line number Diff line change
    @@ -7,4 +7,4 @@
    raiseOnUnderflow:YES
    raiseOnDivideByZero:YES];
    float rounded = [[[NSDecimalNumber decimalNumberWithString:[[NSNumber numberWithFloat:toRound] stringValue]] decimalNumberByRoundingAccordingToBehavior:handler] floatValue];
    NSLog(@"%f", progress);
    NSLog(@"%f", rounded);
  2. Morse-Code created this gist Apr 17, 2014.
    10 changes: 10 additions & 0 deletions RoundFloat.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    float toRound = 0.999322;
    short precision = 3;
    NSDecimalNumberHandler *handler = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundPlain
    scale:precision
    raiseOnExactness:YES
    raiseOnOverflow:YES
    raiseOnUnderflow:YES
    raiseOnDivideByZero:YES];
    float rounded = [[[NSDecimalNumber decimalNumberWithString:[[NSNumber numberWithFloat:toRound] stringValue]] decimalNumberByRoundingAccordingToBehavior:handler] floatValue];
    NSLog(@"%f", progress);