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

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

How to round a decimal

I use this in SQL :

Price = round(Price * 1.08, 2)

I need to do the same thing in C# for a Decimal field "Price".  
How do I do this?   thanks
0
MikeMCSD
Asked:
MikeMCSD
  • 3
  • 2
2 Solutions
 
Bill NolanCommented:
There are several Round() functions in System.Decimal.
0
 
Éric MoreauSenior .Net ConsultantCommented:
have you tried:

Price = Math.Round(Price * 1.08, 2)
0
 
MikeMCSDAuthor Commented:
thanks . .  I'm getting an error "operand * can't be applied to decimal . . .".

pv.Price = Math.Round((pv.Price * 1.08), 2);

any work around for that?



0
Technology Partners: 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!

 
Bill NolanCommented:
Assuming pv.Price is a decimal:

pv.Price = Math.Round((pv.Price * 1.08m), 2);

or

pv.Price = Decimal.Round((pv.Price * 1.08m), 2);
0
 
MikeMCSDAuthor Commented:
excellent, . . thanks
good one Slim ..  I forgot about the "m" thing.

0
 
Bill NolanCommented:
You also seemed to forget about my first post :)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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