[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Masking decimal property in output.

Posted on 2011-03-11
3
Medium Priority
?
414 Views
Last Modified: 2013-12-17
hello,

In a code I'm dealing with a property defined in a class:

public decimal UnitPriceExclTax { get; set; }

I need to write this out into a CSV file however, it shows 4 fraction digits after floating point.

How can I limit or mask it such it only show 2 digits. Rather $30.0000 it should be $30.00 ?

I'm writing it into a CSV file as following:




Thanks,
ak








 
sb.Append(String.Format("\"{0}\"", orderObj.UnitPriceExclTax));

Open in new window

0
Comment
Question by:akohan
3 Comments
 
LVL 6

Assisted Solution

by:jello024
jello024 earned 200 total points
ID: 35113633
This should work >>

sb.Append(String.Format("\"{0}\"", orderObj.UnitPriceExclTax.ToString("N2")));
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 800 total points
ID: 35113742
Or, if you actually need it as a currency:
sb.Append(string.Format("\"{0:C2}\"", orderObj.UnitPriceExclTax));

Open in new window

0
 

Author Comment

by:akohan
ID: 35238329

Thanks!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

865 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