Solved

numbers conversion

Posted on 2008-09-30
3
204 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 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