Which way is better for removing float decimals places or is there a more efficient way?
Rounding is not important, i am interested in displaying the number
Float number;
1- int wholeNumber= Convert.ToInt(number);
string display=wholeNumber.ToString();
2- string [] splitNumber= number.ToString().Split('.');
string display=splitNumber[0];
Here are two oprions that are more efficient:
Simply cast the number instead of calling
Convert.ToInt32:Format the number using a format specifier with zero decimals:
The first one should be slightly faster, as it’s easier to format an integer than an floating point number.
If you want something that really is efficient, you would cast the number to integer, then format it into a string yourself using code that is optimised to do only what you need and nothing more.