.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 10th, 2004, 07:06 PM
talljames talljames is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 15 talljames User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 19 sec
Reputation Power: 0
Question Convert Double to String in C#

Hi all,

I would like to convert a string ("700") to a double (7.00) and then back to a string
("7.00").

My code is like this:
double S = Convert.ToDouble("700")/100.00;
string s = Convert.ToString(S);

You will find that this gives the striing "7" ie it has lost all the zeros and the decimal point!

Does anyone know how to retain the decimal point and zeros?

thanks
James

Reply With Quote
  #2  
Old December 28th, 2004, 09:59 AM
MrBullwinkle MrBullwinkle is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Wild and Wonderful, West Virginia
Posts: 27 MrBullwinkle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to MrBullwinkle Send a message via AIM to MrBullwinkle Send a message via MSN to MrBullwinkle Send a message via Yahoo to MrBullwinkle
If it has digits in those 0s then it wouldn't have dropped them. thus 789 would become 7.89 and your problem would not exist. One way is to just test if the 0s were dropped possibly by getting length of the string before vs after, and adding the '.00' afterwards.


Not sure what you're actually doing, but if its just to divide a string by 100 seems easier to just manipulate the decimal in the string, but if its not a multiple of 10 then its not so easy.

Reply With Quote
  #3  
Old January 20th, 2005, 10:26 AM
thalko thalko is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 1 thalko User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
try something like this...


string
s = "700";
double d = Double.parse(s);
d = d/ 100;
s = d.ToString("0.00");

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > Convert Double to String in C#


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap