Linked Questions
12 questions linked to/from swift: issue in converting string to double
0
votes
0
answers
437
views
Swift : impossible to round a double correctly [duplicate]
I would like to round a double with 2 decimals.
I have tried many ways
- round * 100 /100
- by passing with a string
but it's the same matter
I would like 166.67 but I get 166.66999999
(look at ...
1
vote
0
answers
128
views
Initial unprecise float value [duplicate]
Can someone explain this behaviour to me? Why is the float value initially not as precise as I would expect? Why is the double cast creating an even less precise value?
0
votes
0
answers
68
views
Swift 2.2 : Decimal conversion not working as expected in Xcode [duplicate]
Trying to convert string to decimal and shows unexpected values for some strings such as 8.80 and 9.80 , tried to run some code in playground and Xcode, please refer below screen shots. I suspect this ...
0
votes
1
answer
48
views
Issue in converting string to double [duplicate]
I have mobile bank app.
When user type amount, then convert string to double i have problem
user typed amount example "8.7" is 8.699999999999999 and when i send request it sending 8.699999999999999
...
0
votes
0
answers
23
views
Same operation but totally different digit precision in Swift [duplicate]
I'v tried following code when learning the mutation function of structure type
struct SelfMutaPoint {
var x = 0.0, y = 0.0
mutating func moveBy(x deltaX: Double, y deltaY: Double) {
...
4025
votes
36
answers
616k
views
Is floating-point math broken?
Consider the following code:
0.1 + 0.2 == 0.3 -> false
0.1 + 0.2 -> 0.30000000000000004
Why do these inaccuracies happen?
1
vote
3
answers
3k
views
Round Issue in swift
I have this Info.
let params2: [String: AnyObject] = [
"app_token": myapptoken,
"member_access_token": accessToken!,
"pay_process": 0,
"payamount_credit": 9.87 //hardcode
]
When print ...
2
votes
2
answers
4k
views
Convert JSON data to Double in Swift
I receive the following JSON response:
{
"id": 1,
"value": 519.6365
}
But when I convert the value to Double, I get: 519.63649999999996
How to keep the original value? (without rounding it)
8
votes
1
answer
1k
views
How to keep original double value while parsing in json swift?
I received the following response from server
"transactionInfo": {
"currencyCode": "MYR",
"total": 472.23,
"roomCurrencyCode": "MYR",
"roomTotal": 472.23
}
but when I am ...
0
votes
1
answer
177
views
How to prevent currency with decimal rounds in Swift
Seems to be trivial but I couldn't figure out how to prevent the currency value from Rounding in Swift.
Below is my code:
let halfYearlyPrice = 71.99
var perMonthPrice = (halfYearlyPrice as Double) / ...
1
vote
1
answer
124
views
Why this happens in floating point conversion?
I noticed that some floating points converted differently. This question helps me about floating points however still don't know why this happens? I added two screenshots from debug mode about the ...
0
votes
1
answer
90
views
In Swift 4, what is the correct way of typecasting a String value to a Float value?
I came across a situation where the following code does not work as expected in a project whereas works fine in Playground.
strtof("0.9", nil) //expected to return 0.9
Float("0.9")! //expected to ...