How to round a decimal

Posted on 2011-09-27
Last Modified: 2012-08-13
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
Question by:MikeMCSD
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Expert Comment

by:Bill Nolan
ID: 36712613
There are several Round() functions in System.Decimal.
LVL 70

Accepted Solution

Éric Moreau earned 250 total points
ID: 36712689
have you tried:

Price = Math.Round(Price * 1.08, 2)
LVL 16

Author Comment

ID: 36712769
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?

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!


Assisted Solution

by:Bill Nolan
Bill Nolan earned 250 total points
ID: 36712849
Assuming pv.Price is a decimal:

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


pv.Price = Decimal.Round((pv.Price * 1.08m), 2);
LVL 16

Author Comment

ID: 36712869
excellent, . . thanks
good one Slim ..  I forgot about the "m" thing.


Expert Comment

by:Bill Nolan
ID: 36712879
You also seemed to forget about my first post :)

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to repeat the data 4 30
Need to sort columns in DataGridView 4 36 Markup for Sub Menu 2 39
Nested forach loop to linq 3 25
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

735 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