Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • 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 NolanOwner, Lead Technology ProgrammerCommented:
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Bill NolanOwner, Lead Technology ProgrammerCommented:
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 NolanOwner, Lead Technology ProgrammerCommented:
You also seemed to forget about my first post :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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