Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need a more elegant way of obtaining the integer value of a dollar amount without any rounding taking place ... for example 18.22 should return 18 and 18.99 should return 18. Here is how I'm doing it now ... it works but it feels pretty inelegant. Anyone care to take a stab at prettying this up for me?

string strNumberToRound = numberToRound.ToString();
int index = strNumberToRound.IndexOf(".");
string dollarValue = (index > 0 ? strNumberToRound.Substring(0, index) : numberToRound.ToString());
decimal number1 = Convert.ToDecimal(dollarValue);


Thanks for your help in advance!

What I have tried:

See code snippet above ... I'm using string manipulations to accomplish the task
Posted
Updated 25-Nov-18 12:57pm

1 solution

Never mind guys ... a quick Google search revealed the functionality of

Math.Floor(numberToRound)


Sorry to have bothered you.
 
Share this answer
 

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