I want to extract N number of decimal points after the value without doing round up.
Below is the example :
string val = null;
int numberOfDigitsAfterDecimalPoint = 2;
double val1 = 56423747.61;
double val2 = 56423996.57;
val = ((56423747.61 / 56423996.57) * 100).ToString(); //99.9995587692912
val = String.Format("{0:n" + numberOfDigitsAfterDecimalPoint.ToString() + "}", (100 * Convert.ToDecimal(val)) / 100); //100.00
But problem here is it is rounding up and I am getting 100.00 which I don't want because I want exact value with decimal point i.e 99.99 without any kind of round up.
I searched and came to conclusion(my thinking) that best way to handle this is by extracting number of digits after decimal point with substring method but still I am not sure that whether i am thinking in wrong or right way.
Expected output with numberOfDigitsAfterDecimalPoint = 2 :
99.99
Update
I am not having a fixed value to get after decimal point because it is dependent on numberOfDigitsAfterDecimalPoint variable. Apart from that can have very large value based on which I am calculating val; that is why I was thinking to use substring function in which I won't have any problem related to round off, as oppose to mathematical calculation or math function.
How can I do this in efficient way without compromising any value?