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

P

pebelund

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
 
M

Morten Wennevik

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top