Click here to Skip to main content
14,134,933 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
I want to TRUNCATE, NOT ROUND. I want the output in the messagebox to at 2 decimal places.

Here is the code below.

decimal amountPerHour = Convert.ToDecimal(GlobalVariables._salaryAmount / 52 / 48);

            amountPerHour = TruncateDecimal(0.275, 2);
            MessageBox.Show("The amount is " + amountPerHour.ToString());





Basically the global variable is a number in a database. and its being passed through and basically whatever that value is, i want to be divded and calculate and put at 2 decimal places.

I know the answer is 16.25 but it comes out at either 16 or 16.00 i dont want it rounded. i want it truncated to 16.25

Help Please
Posted
Updated 9-Apr-14 11:56am
v2
Comments
   
Why?! Normally, you don't even need to round anything.
Okay, truncating is a string operation. Any problems with them? :-)
—SA
Chris_Burns 9-Apr-14 18:47pm
   
I've solved it cheers buddy :). Basically, I was calculating the decimal and the outcome was 16. So when i turned it into a double it came up with the 16.023403493458439 etc.. Then i converted back to decimal and inserted that into the SQL database. Thanks anyways :)
ZurdoDev 9-Apr-14 19:22pm
   
Please post as solution so this no longer shows as unanswered.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web05 | 2.8.190518.1 | Last Updated 9 Apr 2014
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100