[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 417
  • Last Modified:

Masking decimal property in output.

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
akohan
Asked:
akohan
2 Solutions
 
jello024Commented:
This should work >>

sb.Append(String.Format("\"{0}\"", orderObj.UnitPriceExclTax.ToString("N2")));
0
 
Carl TawnSystems and Integration DeveloperCommented:
Or, if you actually need it as a currency:
sb.Append(string.Format("\"{0:C2}\"", orderObj.UnitPriceExclTax));

Open in new window

0
 
akohanAuthor Commented:

Thanks!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now