469,272 Members | 1,560 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,272 developers. It's quick & easy.

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

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
1 1922
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.

Similar topics

6 posts views Thread by Richard Steele (Basemap) | last post: by
5 posts views Thread by Rajesh Kr Shukla | last post: by
1 post views Thread by Chris Morse | last post: by
2 posts views Thread by mazdotnet | last post: by
7 posts views Thread by L. Scott M. | last post: by
9 posts views Thread by john coltrane | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.