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)

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 07-24-2008, 06:41 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 97
Default Double to string

Quick problem,

i need to have following conversion (double to string):
  • 123.0 -> '123'
  • 123.123 -> '123.123'
  • 123.00001 -> '123.00001'

i tried stringWithFormat but i cant find a way to show fractal part without trailing zeros, with a precision of current double value. In other words, if there is frac, show them all, no trailing zeros. If no frac - show only part before float separator.

I need to populate double value into UITextView or how it is called (aka TEdit)
Saurman is offline   Reply With Quote
Old 07-25-2008, 05:50 AM   #2 (permalink)
I am evil trapper
 
Join Date: Jul 2008
Location: London
Posts: 299
Default

I need to do something similar but have left it for now while I work on other things. Let me know if you figure it out.
trapper is offline   Reply With Quote
Old 07-26-2008, 01:43 PM   #3 (permalink)
Registered Member
 
tawpie's Avatar
 
Join Date: Jul 2008
Posts: 347
Default

this gets very very messy, especially if you localize. But if all you want to do is to trim off the trailing zeros you have to mess with the string directly, after it's been converted. You might take a look at stringByReplacingOccurances... (there are three methods).

NSNumberFormatter is the route I'd advise you to take, as it'll allow you to deal with localization seamlessly BUT be aware that it has its own diffugueatltees and there might be some bugs that need working around.
tawpie is offline   Reply With Quote
Old 05-04-2009, 07:45 AM   #4 (permalink)
I am evil trapper
 
Join Date: Jul 2008
Location: London
Posts: 299
Default

Ok forget that... just found a major bug. Back to the drawing board for me
__________________
Black or Red - Possibly the first ever iPhone drinking game! Try it tonight.
Kings - My second drinking game, bigger and better!

Last edited by trapper; 05-04-2009 at 08:43 AM.
trapper is offline   Reply With Quote
Reply

Bookmarks

Tags
convert, double, string

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: 279
17 members and 262 guests
2WeeksToGo, ADY, dacapo, Dani77, Fritzer, ghost, HDshot, headkaze, iDifferent, mer10, mystic.purple, Rudy, smethorst, stoneage, superg, tathaastu, Zool
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,878
Threads: 89,224
Posts: 380,732
Top Poster: BrianSlick (7,129)
Welcome to our newest member, olga2000
Powered by vBadvanced CMPS v3.1.0

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