# Control P5 Slider rounds incorrectly on negative number

**URL:** <https://discourse.processing.org/t/control-p5-slider-rounds-incorrectly-on-negative-number/44413>\
**Category:** Libraries\
**Created:** [May 10, 2024, 9:11pm UTC](https://discourse.processing.org/t/control-p5-slider-rounds-incorrectly-on-negative-number/44413 "2024-05-10T21:11:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dfecker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dfecker/32/19342_2.png) [@dfecker](https://discourse.processing.org/u/dfecker)\
**Post date:** [May 10, 2024, 9:11pm UTC](https://discourse.processing.org/t/control-p5-slider-rounds-incorrectly-on-negative-number/44413/1 "2024-05-10T21:11:44Z")

</div>

When the Slider reaches -40 it return a -39.99 and rounds down to a -39. If every other value returned in this example is an int and base 10 why is the -40 off? And how do I fix it so my numbers are multiples of 10 from -100 to 0?

```auto
import controlP5.*;

ControlP5 cp5;
Slider testSlider;

void setup() {
  size(300,100);
  cp5 = new ControlP5(this);

  testSlider = cp5.addSlider("test_slider")    
     .setSize(200,20)
     .setRange(-100,0)
     .setValue(-40)
     .setNumberOfTickMarks(11)
     .setDecimalPrecision(0)
     ;
}

void draw() {
}

```

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [May 11, 2024, 12:48pm UTC](https://discourse.processing.org/t/control-p5-slider-rounds-incorrectly-on-negative-number/44413/2 "2024-05-11T12:48:19Z")

</div>

The problem is that the number has _ **not been rounded** _ despite having set the decimal precision to `0`

Here is the method that returns a slider’s value, note it uses Processing’s map function.

```auto
	@Override public float getValue( ) {
		return PApplet.map( _myValue , 0 , 1 , _myMinReal , _myMaxReal );
	}

```

If we simulate this with

```auto
float value = map(0.6, 0, 1, -100, 0);
float rounded = round(value);
println(value, rounded);

```

we get `-39.999996 -40.0` which supports my statement in the first paragraph.

I can think of no way to make the slider display the rounded value without editing the controlP5 library source code and rebuilding it.
