Solved

Masking decimal property in output.

Posted on 2011-03-11
3
362 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 50 total points
Comment Utility
This should work >>

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

Accepted Solution

by:
Carl Tawn earned 200 total points
Comment Utility
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
Comment Utility

Thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

8 Experts available now in Live!

Get 1:1 Help Now