How to shift all the whole numbers in a double to the right of the point ? Example i have 5342, i want the function to return 0.5342. I do not know the number of digits in the double, it's randomly generated. Should be fairly easy but i can't find any answers.
This sounds like a pretty bizarre task, to be honest, but you could use:
while (Math.Abs(value) >= 1)
{
value = value / 10;
}
That will go into an infinite loop if the input is infinity though - and you may well lose information as you keep dividing. The latter point is important - if what you're really interested in is the decimal representation, you should consider using decimal
instead of double
.
You could potentially use a mixture of Math.Log
and Math.Pow
to do it, but the above is probably what I'd start with.
See more on this question at Stackoverflow