|
-
Jul 28th, 2003, 08:15 AM
#1
Thread Starter
Junior Member
Sticking a period in the middle of a string ;)
How do I stick a period in the middle of a string?
I have an integer, for example 123456, and I need to display it as 1234.56 as in currency format. I've tried doing an x.ToString("0.00") but it adds a '.00' at the end (i.e. 123456.00) and x.ToString("#.##") doesn't seem to do anything at all. How is this done? Thanks in advance.
-
Jul 28th, 2003, 09:43 AM
#2
Hyperactive Member
Ok I am sure there is an easier way but this should work!
Code:
int number = 12345;
string toFormat = number.ToString();
string finalnumber = toFormat.Substring(0,toFormat.Length-2);
finalnumber = finalnumber + "."+ toFormat.Substring(finalnumber.Length-1,toFormat.Length - (finalnumber.Length-1));
textBox1.Text = finalnumber;
Hope I could help with that,
Stephan
Keep Smiling - even if its hard 
Frankie Says Relax, wossname Says Yeah!
wossname:--Currently I'm wearing a gimp suit and a parachute.
C# - Base64 Blog
-
Jul 28th, 2003, 12:16 PM
#3
Code:
int val = 123456;
string sVal = val.ToString();
string formatted = sVal.Insert(sVal.Length - 2, ".");
-
Jul 28th, 2003, 06:21 PM
#4
Hyperactive Member
Any of these will do that for you:
Code:
x.ToString( n2 );
x.ToString( N2 );
x.ToString( f2 );
x.ToString( F2 );
The help text for this is hidden under "Standard Numeric Format Strings" in MSDN...
-
Jul 29th, 2003, 03:23 AM
#5
Hyperactive Member
I knew there are easier ways to do it!
Keep Smiling - even if its hard 
Frankie Says Relax, wossname Says Yeah!
wossname:--Currently I'm wearing a gimp suit and a parachute.
C# - Base64 Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|