Solved

Masking decimal property in output.

Posted on 2011-03-11
3
392 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 50 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 200 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…
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 Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 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