Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Limit decimal to two decimal places
I'm calculating a monthly income by using this in my code:
[code]Decimal userInc = Convert.ToDecimal(sdrInc.ToString());
userIncMonthly += (userInc / 12);
txtMonthlyIncome.Text = "$" + userIncMonthly.ToString();[/code]
It displays a large amount of digits behind the decimal place. The way I've been removing those is this way:
[code]txtMonthlyIncome.Text = txtMonthlyIncome.Text.Remove(8, txtMonthlyIncome.Text.Length - 8);[/code]
This is assuming that the number is in the format $XXXX.XX. Now, I want to find the decimal place and then delete everything after 2 digits past the decimal place. So I would like my code to do this:
[code]txtMonthlyIncome.Text = txtMonthlyIncome.Text.Remove([decimal place index]+2, txtMonthlyIncome.Text.Length - [decimal place index] + 2);[/code]
What's the easiest way to do that or is there a way I can make my calculation not allow more than two decimal places?
0 · ·