Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 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.

C#
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
Sergey Alexandrovich Kryukov 9-Apr-14 18:17pm    
Why?! Normally, you don't even need to round anything.
Okay, truncating is a string operation. Any problems with them? :-)
—SA
[no name] 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900