[Webinar] Streamline your web hosting managementRegister Today

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
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.

 
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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

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