Solved

numbers conversion

Posted on 2008-09-30
3
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

717 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