I need to develop a function in c# to validate some customized formats (not the native ones). In order to do that I need to analyse char by char of the value that I am getting to find out if it is in the correct format.
The values that I will get could be something like:
1.00020
4.00155001
6.000000
5.10000000000
0.00000000000000
However I am struggling to convert those numbers to string keeping the same shape. I can't really use the formats provided by the framework because I don't know how many decimals places the value that I will get has.
To get around of this I tried to use (BitConverter.GetBytes(decimal.GetBits((decimal)valueCheck)[3])[2])
to find out the number of decimal places and then use .ToString("Format")
, however it does not consider 0's at the end.
The question is simple: How can I convert a double to string in order to always keep exactly the same number and decimal places when I don't know how many decimal places my input has?