I am trying to convert a double type to fixed type representation. Depending on the input selected, my raw values can be for example 0.00996, 989.15, 1600.25, 89.72 and so on. The point here is that all my input values are always positive but the number of digits before (and after) the decimal place can vary. I am trying to convert these double types to fixed point representation via suitable scaling. I have tried 2.14 scaling (multiply by 16,384) but am not sure how to extend that to the case of variable number of digits before the decimal place. Also, how can I best ensure the maximum accuracy/precision in the converted values? Any help would be greatly appreciated. Thank you.
Code I am using:
fixedScale = (int) Math.Pow(2.0, 64.0); int new_val = (int) (fixedScale * value);
Decimal new_value = (Decimal)original_value