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?

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.


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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below.…

734 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