Solved

numbers conversion

Posted on 2008-09-30
3
196 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now