Solved

How to round a decimal

Posted on 2011-09-27
6
246 Views
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
0
Comment
Question by:MikeMCSD
[X]
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
6 Comments
 
LVL 7

Expert Comment

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

Accepted Solution

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

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

Author Comment

by:MikeMCSD
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?



0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 7

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);

or

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

Author Comment

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

0
 
LVL 7

Expert Comment

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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

705 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