Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

TTTUnitOfInformationFormatter: Support bigger numbers #34

Merged
merged 3 commits into from about 1 year ago

3 participants

Matthias Mattt Thompson sycx
Matthias

Fixes a problem when getting a string from a big number because of casting the result of a multiplication to integer.

Mattt Thompson
Owner
mattt commented March 03, 2013

Thanks for the patch, @brutella.

Would e83d1f4 work the same if we used numberWithLongLong: instead of numberWithDouble:?

Matthias

I thought about that too. It still works with long long.

Mattt Thompson mattt merged commit 076d090 into from March 08, 2013
Mattt Thompson mattt closed this March 08, 2013
Mattt Thompson
Owner
mattt commented March 08, 2013

Great. Yeah, long long makes more sense for integer values. Thanks, @brutella.

sycx

Use long long here is incorrect.
result will lose precision.

should revert this line.

Matthias brutella deleted the branch October 09, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
6  FormatterKit/TTTUnitOfInformationFormatter.m
@@ -221,20 +221,20 @@ - (NSString *)stringFromNumberOfBits:(NSNumber *)number {
221 221
         doubleValue /= [self scaleFactorForPrefix:prefix];
222 222
     }
223 223
 
224  
-    return [NSString stringWithFormat:NSLocalizedStringWithDefaultValue(@"Unit of Information Format String", @"FormatterKit", [NSBundle mainBundle], @"%@ %@", @"#{Value} #{Unit}"), [_numberFormatter stringFromNumber:[NSNumber numberWithDouble:doubleValue]], unitString];
  224
+    return [NSString stringWithFormat:NSLocalizedStringWithDefaultValue(@"Unit of Information Format String", @"FormatterKit", [NSBundle mainBundle], @"%@ %@", @"#{Value} #{Unit}"), [_numberFormatter stringFromNumber:[NSNumber numberWithLongLong:doubleValue]], unitString];
225 225
 }
226 226
 
227 227
 - (NSString *)stringFromNumber:(NSNumber *)number
228 228
                         ofUnit:(TTTUnitOfInformation)unit
229 229
 {
230  
-    return [self stringFromNumberOfBits:[NSNumber numberWithInteger:(TTTNumberOfBitsInUnit(unit) * [number integerValue])]];
  230
+    return [self stringFromNumberOfBits:[NSNumber numberWithLongLong:(TTTNumberOfBitsInUnit(unit) * [number integerValue])]];
231 231
 }
232 232
 
233 233
 - (NSString *)stringFromNumber:(NSNumber *)number
234 234
                         ofUnit:(TTTUnitOfInformation)unit
235 235
                     withPrefix:(TTTUnitPrefix)prefix
236 236
 {
237  
-    return [self stringFromNumber:[NSNumber numberWithDouble:([self scaleFactorForPrefix:prefix] * [number integerValue])] ofUnit:unit];
  237
+    return [self stringFromNumber:[NSNumber numberWithLongLong:([self scaleFactorForPrefix:prefix] * [number integerValue])] ofUnit:unit];
238 238
 }
239 239
 
240 240
 #pragma mark - NSCoding
BIN  Localizations/en.lproj/FormatterKit.strings
Binary file not shown
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.