月圆之夜,紫禁之巅,一剑西来,天外飞仙。

0%

iOS 实现简易的计算器

先看效果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
主要代码:

NSDecimalNumber * number1 = [NSDecimalNumber decimalNumberWithString :@“12.5”];

NSDecimalNumber * number2 = [NSDecimalNumber decimalNumberWithString :@“2.5”];

// 加

NSDecimalNumber * sumNum = [number1 decimalNumberByAdding :number2];

// 减

NSDecimalNumber * subNum = [number1 decimalNumberBySubtracting :number2];

// 乘

NSDecimalNumber * multiNum = [number1 decimalNumberByMultiplyingBy :number2];

// 除

NSDecimalNumber * dividNum = [number1 decimalNumberByDividingBy :number2];