By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,017 Members | 1,169 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,017 IT Pros & Developers. It's quick & easy.

Converting string to currency/formatting in thousands.aspx (.NET)

P: n/a
Hi
I got an .aspx that got the following code (example)

<td width="120">
<% = row["valueinString"] %>
</td>

row["string"] takes a value from a SQL db, that is a string of numbers.
On the webbsite I want this to show as value formatted in thousands
(example: I get the value 12345678, and I want it to show like 12 345
678 OR even like, 12.345.678 (currency value).

Anyone have an idea of how to make this happen? (newbeginner problem
probably, but that is what I am so :P )

Regards
Peter

Oct 23 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Mon, 23 Oct 2006 12:09:34 +0200, pebelund <pe******@gmail.comwrote:
Hi
I got an .aspx that got the following code (example)

<td width="120">
<% = row["valueinString"] %>
</td>

row["string"] takes a value from a SQL db, that is a string of numbers.
On the webbsite I want this to show as value formatted in thousands
(example: I get the value 12345678, and I want it to show like 12 345
678 OR even like, 12.345.678 (currency value).

Anyone have an idea of how to make this happen? (newbeginner problem
probably, but that is what I am so :P )

Regards
Peter
Hi Peter,

Would you be looking for the number format specifier in ToString(). Using
C or c as the specifier would output the number as money, and using N or n
would do the same without the currency symbol. The output is culture
specific. If you don't want the default two decimals, use C#, c#, N#, n#
where # is the number of decimals

If you have a string 12345678 you would first need to parse it to an
integer (or another number of your choice).

string s = "12345678";
int n = int.Parse(s);

string output = n.ToString("c");

output =
$12,345,678.00 (en-US)
12,345,678.00 (en-GB)
kr 12*345*678,00 (nb-NO)

--
Happy Coding!
Morten Wennevik [C# MVP]
Oct 23 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.