Solved

numbers conversion

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# GridRow get Old/New Value 1 55
VB.NET HttpWebRequest 12 56
how to truncate multiple tables from SQL Server Database using Stored procedure 8 49
Run time Error 4 34
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

911 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

19 Experts available now in Live!

Get 1:1 Help Now