Solved

How to round a decimal

Posted on 2011-09-27
6
242 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vb.net dynamic formulas in runtime 11 63
ADO.NET ENTITY DATA MODEL 3 32
System.Speech 2 16
Windows Media Player 2 16
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

15 Experts available now in Live!

Get 1:1 Help Now