Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-21-2009, 06:02 AM   #1 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: Colombo, Sri Lanka
Posts: 58
tharindufit is on a distinguished road
Send a message via Yahoo to tharindufit Send a message via Skype™ to tharindufit
Default Convert float value to display with Commas

Hi
I have float variables that stores my currency values, I want to display these values in a string with commas at each 3 digits, can I do it with Objective C. I am new to the language. Please help me to solve this.
For example,
Code:
float ft = 12333.8905;
NSString *strFloat = [NSString stringWithFormat:@"%.2f",ft];
this will show my float value with 2 decimal places 12333.89 , But I want it to be displayed as 12,333.89
Can I do it with objective-C. I want to create a string like above from my float value.

Thanks
Tharindu
tharindufit is offline   Reply With Quote
Old 01-21-2009, 06:31 AM   #2 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: Colombo, Sri Lanka
Posts: 58
tharindufit is on a distinguished road
Send a message via Yahoo to tharindufit Send a message via Skype™ to tharindufit
Default

Code:
NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];
NSString *str = [nf stringFromNumber:[NSNumber numberWithFloat:floatvar]];
tharindufit is offline   Reply With Quote
Old 01-16-2012, 08:29 PM   #3 (permalink)
HTO
Registered Member
 
Join Date: Jan 2012
Posts: 1
HTO is on a distinguished road
Default

Quote:
Originally Posted by tharindufit View Post
Hi
I have float variables that stores my currency values, I want to display these values in a string with commas at each 3 digits, can I do it with Objective C. I am new to the language. Please help me to solve this.
For example,
Code:
float ft = 12333.8905;
NSString *strFloat = [NSString stringWithFormat:@"%.2f",ft];
this will show my float value with 2 decimal places 12333.89 , But I want it to be displayed as 12,333.89
Can I do it with objective-C. I want to create a string like above from my float value.

Thanks
Tharindu
Try this?


NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc] init];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
myLabel.text = [currencyFormatter stringFromNumber:someAmount];
HTO is offline   Reply With Quote
Reply

Bookmarks

Tags
float, nsstring, objective - c

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 401
10 members and 391 guests
Atatator, buggen, guusleijsten, j.b.rajesh@gmail.com, morterbaher, QuantumDoja, sacha1996, Sami Gh, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,122
Posts: 402,907
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:35 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0