Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,025 questions

51,979 answers

573 users

How to convert float to string in Swift

3 Answers

0 votes
import Foundation

let f = 839014.56217

let s = NSString(format: "%.6f", f)

print(s)



/*
run:
 
839014.562170
 
*/

 



answered Oct 31, 2024 by avibootz
edited Oct 31, 2024 by avibootz
0 votes
import Foundation

let f = 839014.56217

let s = f.description

print(s)



/*
run:
 
839014.56217
 
*/

 



answered Oct 31, 2024 by avibootz
0 votes
import Foundation

let f = NSNumber(value: 839014.56217)

let formatter : NumberFormatter = NumberFormatter()
formatter.numberStyle = .decimal

let s = formatter.string(from: f)!

print(s)



/*
run:
 
839,014.562
 
*/

 



answered Oct 31, 2024 by avibootz

Related questions

1 answer 68 views
68 views asked Jan 18, 2025 by avibootz
1 answer 176 views
176 views asked Jun 22, 2021 by avibootz
3 answers 121 views
1 answer 93 views
...