# Mapping to decimals

Hi,

I have issue where I need to map the data i'm sending with osc.

This is accelerometer with the output of about -100 tot 300 to 0.000 to 1.

I've tried a couple of examples I found on this forum and the latest gave me this. But it's really not a solution.

Is there any way of achieving this properly.

``````  float Xmap = (norm.XAxis / 100.00)* 10.00;
float XmapRound = Xmap + 0.001 /10;
``````
``````float map(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

float mapped = map(norm.XAxis, -100.0, 300.0, 0.0, 1.0);
``````

Pieter

Does map() function support float numbers as arguments?

GolamMostafa:
Does map() function float numbers as arguments?

The map function I defined in my previous post does.

beyondal:
This is accelerometer with the output of about -100 tot 300 to 0.000 to 1.

I've tried a couple of examples I found on this forum and the latest gave me this. But it's really not a solution.

Is there any way of achieving this properly.

``````  float Xmap = (norm.XAxis / 100.00)* 10.00;
``````

float XmapRound = Xmap + 0.001 /10;

``````  float Xmap;
Xmap = norm.XAxis / 100.00;  Change the range -100,300 to the range -1.0,3.0
Xmap *= 10.00;  // Change the range -1.0,3.0 to the range -10.0,30.0
float XmapRound;
XmapRound = Xmap + (0.001 /10);  // Add 0.0001 to the value
// The resulting range is -9.9999,30.0001
``````

This is what your code should have done:

``````  // Map the accelerometer output from the range -100 to 300 to the range 0.0 to 1.0
float Xmap = norm.XAxis + 100.0;  // Change the range -100,300 to the range 0.0,400.0
Xmap /= 400.0;  // Change the range 0.0,400.0 to the range 0.0,1.0
``````

It's not clear what you intended to do with the "rounding". Did you want to round it up to two decimal places?

``````  // Round Xmap up to two decimal places:
float XmapRound = ((int)((Xmap + 0.005) * 100.0)) / 100.0;
``````