Solved

How to round a decimal

Posted on 2011-09-27
6
241 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
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:Slimfinger
ID: 36712613
There are several Round() functions in System.Decimal.
0
 
LVL 69

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 7

Assisted Solution

by:Slimfinger
Slimfinger 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:Slimfinger
ID: 36712879
You also seemed to forget about my first post :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now