GPWiki.org
GPWiki.org
It is currently Sat May 18, 2013 4:47 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Aug 04, 2011 8:46 am 
Ankle Nibbler
User avatar

Joined: Tue Dec 20, 2005 12:28 am
Posts: 140
How do you output floating point number the way you want?

In C# code I have a floating point variable number that I want presented as a string but I want it formatted in a particular way. if I have a float number, like, 0.532492829839, for example and I want it represented in C# code as "53.24%", how would I do that? I imagine it would be done using IFormatProvidre and float.parse. But I have not done it before. First of all, I guess I should multiply the number by 10, but how would I pick a number of decimal place?


Top
 Profile  
 
PostPosted: Thu Aug 04, 2011 11:05 am 
Novice

Joined: Wed Aug 03, 2011 10:23 pm
Posts: 7
Check out String.Format. It accepts your variable and a format string, so you can format it as a string any way you want.

Quote:
You can format numeric results by using the String.Format method, or through the Console.Write method, which calls String.Format. The format is specified using format strings. The following table contains the supported standard format strings. The format string takes the following form: Axx, where A is the format specifier and xx is the precision specifier. The format specifier controls the type of formatting applied to the numerical value, and the precision specifier controls the number of significant digits or decimal places of the formatted output.



Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group