Solved

numbers conversion

Posted on 2008-09-30
3
201 Views
Last Modified: 2013-11-05
Hi,

I'm reading data from XML. Some of them denote prices. There is a problem that some prices are for example 1562,0000. There is more zeros than is normal :-) I'm sending this data out and other application shows bad prices.

Do you know how to process this data to display correctly on the other side?

thanks
0
Comment
Question by:xRalf
3 Comments
 
LVL 15

Assisted Solution

by:angus_young_acdc
angus_young_acdc earned 100 total points
ID: 22603354
The following site should help you format them correctly:
http://blog.stevex.net/index.php/string-formatting-in-csharp/
0
 
LVL 6

Author Comment

by:xRalf
ID: 22603715
Thanks for link, which methods would you use for formatting the string to remove the comma and redundant zeros?
0
 
LVL 4

Accepted Solution

by:
Joni Kettunen earned 400 total points
ID: 22603756
Depending on your culture and what results you want, here is one example. It is based on same information angus_young_acdc has shown.

First given number is formatted as currency string. Note that currency is shown as specified in current culture (System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat).

Of course you might want to show result as a generic number. You can define how many digits is shown jut by adding number after format: n0, n1, n2, n3... to show specified number of digits. This is not usually mentioned in documentation.
decimal result = Convert.ToDecimal("1562,0000");
 
// Currency string -> $1,562.00 or 1 562,00 ¬
String.Format("{0:c}", result);
// Number string -> 1,562.00
String.Format("{0:n}", result);
// Number string -> 1,562
String.Format("{0:n0}", result);
// Number string -> 1,562.000
String.Format("{0:n3}", result);

Open in new window

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What's the most efficient way to load up a couple of large table in C#? 5 45
SQL Login 17 51
Wav problem 4 27
Call Controller Action Method from ASPX 2 15
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question