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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

AppFusion - 6 in 1!
($0.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-27-2012, 06:23 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 8
Default Changing Numbers to Words Like 10000 to 10K

So i am making an app for electrical engineering and I have a problem that I tried to search Google for but have no idea een where to start looking or what to search for.

I get numbers like 2000, 10000, 120000, 14000000 and so on and was wondering how to detect the amount of zeros and change it to 2K, 10K, 120K, 14M and the like.

Any info on how to do this or a link to somewhere taht shows how to do it would be awesome.
dragon2777 is offline   Reply With Quote
Old 01-27-2012, 06:31 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,187
Default

That sounds pretty simple. Which part of the code are you struggling with? Can you show what you have so far?
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 01-27-2012, 06:32 PM   #3 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Seattle, WA
Posts: 253
Default

pretty simple to write your own function. I have something similar for one of my apps:


NSString *label = [NSString stringWithFormat:@"$%d", money];

if(money>1000)
label = [NSString stringWithFormat:@"$%.1fk", (float)money/1000];
if(money>10000)
label = [NSString stringWithFormat:@"$%dk", money/1000];
if(money>1000000)
label = [NSString stringWithFormat:@"$%.1fM", (float)money/1000000];
if(money>10000000)
label = [NSString stringWithFormat:@"$%dM", money/1000000];
__________________
Check out my apps

RickSDK is offline   Reply With Quote
Old 01-27-2012, 06:34 PM   #4 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 8
Default

Quote:
Originally Posted by dljeffery View Post
That sounds pretty simple. Which part of the code are you struggling with? Can you show what you have so far?
honestly i have never really done any string manipulation in objective c i havent really even joined two strings together. So basically on this i have nothing done and am not even sure where to start
dragon2777 is offline   Reply With Quote
Old 01-27-2012, 06:39 PM   #5 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,187
Default

Quote:
Originally Posted by dragon2777 View Post
honestly i have never really done any string manipulation in objective c i havent really even joined two strings together. So basically on this i have nothing done and am not even sure where to start
Well, you'll never get far if you don't start. You should start by thinking about what it means to translate 1000 to 1K, 1000000 to 1M, etc. And then look in the docs for help on how to do the necessary string manipulation, which is a totally separate task.

This bit is probably going to be the easiest part of your app to do.
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 01-27-2012, 07:07 PM   #6 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 8
Default

Quote:
Originally Posted by RickSDK View Post
pretty simple to write your own function. I have something similar for one of my apps:


NSString *label = [NSString stringWithFormat:@"$%d", money];

if(money>1000)
label = [NSString stringWithFormat:@"$%.1fk", (float)money/1000];
if(money>10000)
label = [NSString stringWithFormat:@"$%dk", money/1000];
if(money>1000000)
label = [NSString stringWithFormat:@"$%.1fM", (float)money/1000000];
if(money>10000000)
label = [NSString stringWithFormat:@"$%dM", money/1000000];
thanks just what i needed. just have to modify some things like no $ and add Ohms haha and change some of the expressions but i understand how to do this now
dragon2777 is offline   Reply With Quote
Old 01-27-2012, 07:09 PM   #7 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 8
Default

Quote:
Originally Posted by dljeffery View Post
Well, you'll never get far if you don't start. You should start by thinking about what it means to translate 1000 to 1K, 1000000 to 1M, etc. And then look in the docs for help on how to do the necessary string manipulation, which is a totally separate task.

This bit is probably going to be the easiest part of your app to do.
I always learn better when i see the code but thank you i spend so much time looking at the stupid apple docs haha.

The real problem was that I didnt really know where to start looking but I have a better understanding now.
dragon2777 is offline   Reply With Quote
Reply

Bookmarks

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: 625
22 members and 603 guests
ADY, bandley, BrianSlick, Creativ, dacapo, Dattee, djbrooks111, gbenna, HDshot, IphoneSdk, iseff, jakerocheleau, jbro, joeallenpro, kampftrinker, linkmx, mer10, nimesh_158, Reyna, ukneeq, yurikus
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 160,619
Threads: 89,833
Posts: 383,490
Top Poster: BrianSlick (7,244)
Welcome to our newest member, yurikus
Powered by vBadvanced CMPS v3.1.0

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