Skip to main content
added 20 characters in body
Source Link
David Heffernan
  • 616.2k
  • 46
  • 1.1k
  • 1.5k

If you want a fixed point representation then you simply need to decide on the scale. Once you have decided that you convert from floating to fixed like this:

int fixedfixedValue = (int)Math.Round(float*ScalefloatValue*Scale); 

And in the other direction like this:

double floatfloatValue = (double)fixedfixedValue/Scale; 

As to what scale to use, that depends on what you are trying to achieve and what the input data are.

If you want a fixed point representation then you simply need to decide on the scale. Once you have decided that you convert from floating to fixed like this:

int fixed = (int)Math.Round(float*Scale); 

And in the other direction like this:

double float = (double)fixed/Scale; 

As to what scale to use, that depends on what you are trying to achieve and what the input data are.

If you want a fixed point representation then you simply need to decide on the scale. Once you have decided that you convert from floating to fixed like this:

int fixedValue = (int)Math.Round(floatValue*Scale); 

And in the other direction like this:

double floatValue = (double)fixedValue/Scale; 

As to what scale to use, that depends on what you are trying to achieve and what the input data are.

Source Link
David Heffernan
  • 616.2k
  • 46
  • 1.1k
  • 1.5k

If you want a fixed point representation then you simply need to decide on the scale. Once you have decided that you convert from floating to fixed like this:

int fixed = (int)Math.Round(float*Scale); 

And in the other direction like this:

double float = (double)fixed/Scale; 

As to what scale to use, that depends on what you are trying to achieve and what the input data are.