?
Solved

Masking decimal property in output.

Posted on 2011-03-11
3
Medium Priority
?
405 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
[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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 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