質問編集履歴
1
質問編集追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -13,4 +13,19 @@
|
|
13
13
|
print(result as Any) // -> Optional(86.25960000000001)
|
14
14
|
let resultStr = result?.stringValue
|
15
15
|
print(resultStr as Any) // -> Optional("86.25960000000001")
|
16
|
+
```
|
17
|
+
|
18
|
+
数値によってはdooubleValueで出力すると変になったりします。
|
19
|
+
|
20
|
+
```swift
|
21
|
+
let expression = NSExpression(format: "85.2596+85.2")
|
22
|
+
let result = expression.expressionValue(with: nil, context: nil) as? NSNumber
|
23
|
+
|
24
|
+
if let resultValue = result?.doubleValue {
|
25
|
+
print(resultValue) // -> 170.45960000000002
|
26
|
+
}
|
27
|
+
|
28
|
+
if let resultValue = result?.stringValue {
|
29
|
+
print(resultValue) // -> 170.4596
|
30
|
+
}
|
16
31
|
```
|