0

服务器有一个 Java Bean,它有一个实例变量类型BigDecimal,但 Objective-C 不能映射它!我试过了NSNumber,但没有用。有人知道如何解决吗?

4

2 回答 2

0

使用 NSDecimalNumber 而不是 NSNumber。

这是将字符串转换为 NSDecimal 的代码

-(NSDecimal) getDecimalFromString:(NSString*)representationString {
    NSDecimal result;
    NSScanner *theScanner = [[NSScanner alloc] initWithString:representationString];
    [theScanner setLocale:[NSLocale currentLocale]];
    [theScanner scanDecimal:&result];

    return result;
}
于 2014-05-30T09:29:34.447 回答
0

试试这个可能有用

    NSDecimalNumber *a = [NSDecimalNumber decimalNumberWithString:@"9999999999999999999999999999999999.99999999999"];
    NSDecimalNumber *b;
    NSDecimalNumber *half = [NSDecimalNumber decimalNumberWithString:@"999999999.9999999999"];
    b = [half decimalNumberByAdding:a]; 
    NSLog(@"The subtration :%@",b);
于 2014-05-30T09:05:36.037 回答