# Analog mapping round bottom and upper to zero and 100, no negative value?

Hey all, newbie here trying to map analog input from 0-1023 to 0-100 with

``````  finNum = map(myNum, 10, 1023, 0, 100);
``````

my issue is that sometimes lowest number my pots puts out would be like 15 or 18. If I change the code to

``````  finNum = map(myNum, 100, 1023, 0, 100);
``````

It works but then I sometimes get negative value, how to write the code above to read only 0-100, no negative value?

Maybe the constrain function is what you need?

First, let's establish what 0 and 1023 means. 0 means 0 volts is detected on the analog pin. For a pot to give a value of 0, it would need to provide infinite resistance, or completely open the circuit. 1023, means the voltage on the pin is equal to analogReference(), which by default is the operating voltage for the microcontroller. For a pot to give a value of 1023, it would need to provide 0 resistance, or a short circuit on the pin. map() simply creates a ratio, so if 0-1023 is mapped to 0-100, it does not establish that only a value between 0 and 100 will be reported. If a value greater than 1023 or less than 0 is mapped, it will be above 100 or below 0, following the scale set.

I guess my pots a crap because they never report 0, minimum number they report are around 170 t0 1023.

`````` finNum = map(myNum, 170, 1023, 0, 100);
``````