Krutarth Patel Krutarth Patel - 3 months ago 6
Swift Question

How to Split String at decimal place in swift?

According to Rules when i round up and round down string the

output
is like this.

1.41 -> 1.40
1.49 -> 1.50

But its a bit different in my case :

i want my string to round down always

like if string is 1.46 i want to get 1.40.

can you please help me to solve this?

Answer

Use floor

let foo = floor(1.49 * 10) / 10
print(foo) //1.4

let bar = floor(6.71 * 10) / 10
print(bar) //6.7
Comments