Nextion screen does not show decimals

Hallo

I'm trying to make a nextion screen to my car.

I'm trying to get it to display turbo boost with a 100psi pressure transducer.

but I will convatere psi to bar, but I can not get the screen to display numbers after the period if the number is 1.21bar shows only 1 bar

#include "Nextion.h"
int boostpin = 0;

//page 1
NexProgressBar j1  = NexProgressBar(1, 4, "j1");
NexProgressBar j0  = NexProgressBar(1, 1, "j0");
NexNumber n0 = NexNumber(1, 8, "n0");
NexNumber n1 = NexNumber(1, 9, "n1");
NexNumber n2 = NexNumber(1, 10, "n2");

//Page 2

NexProgressBar j1  = NexProgressBar(2, 4, "j1");
NexProgressBar j0  = NexProgressBar(2, 1, "j0");
NexNumber n0 = NexNumber(2, 9, "n0");
NexNumber n1 = NexNumber(2, 10, "n1");
NexNumber n2 = NexNumber(2, 11, "n2");


void setup() {
  nexInit();
 
}
void loop() {
  
  int sensorValue = analogRead(boostpin);
  int psi = map(sensorValue, 120, 1023, 0, 100);
 
 float boostBar = psi*0.0689475728;

  n1.setValue(boostBar);

  
  j1.setValue(psi);

}

Here is the doc on the screen:
http://wiki.iteadstudio.com/Nextion_Instruction_Set

here I have bought it:
nextion

/Bruno

I have also tried to convert the number into a char, but still shows no desimaler

#include "Nextion.h"

int boostpin = 0;

char buffer[100] = {0};

//page 1
NexProgressBar j1  = NexProgressBar(1, 4, "j1");
NexProgressBar j0  = NexProgressBar(1, 1, "j0");
NexNumber n0 = NexNumber(1, 8, "n0");
//NexNumber n1 = NexNumber(1, 9, "n1");
NexNumber n2 = NexNumber(1, 10, "n2");

NexText t6 = NexText(1, 12, "t6");

//Page 2

NexProgressBar j3  = NexProgressBar(2, 4, "j3");
NexProgressBar j2  = NexProgressBar(2, 1, "j2");
NexNumber n3 = NexNumber(2, 9, "n3");
NexNumber n4 = NexNumber(2, 10, "n4");
NexNumber n5 = NexNumber(2, 11, "n5");


void setup() {
  nexInit();
 Serial.begin(9600);
}
void loop() {
  
  int sensorValue = analogRead(boostpin);
  int psi = map(sensorValue, 120, 1023, 0, 100);

  j1.setValue(psi);
  
 float boostBar = psi*0.0689475728;

 // n1.setValue(boostBar);

j1.setValue(psi);

  memset(buffer, 0, sizeof(buffer));
    itoa(boostBar, buffer, 10);
    
    t6.setText(buffer);
    //t6.setText(boostBar);
    Serial.println(boostBar);
  }

itoa(boostBar, buffer, 10);

That converts an integer to ASCII, you have a float.

okay how do i convert a float to ASCII?

I haven't done so for years because in embedded systems you normally work with integers for speed reasons and only format for a human if required.

But look up ftoa()

You need 'dtostrf()'.

Note that 'width' is the minimum width, as the example below shows:-

void setup()
{
    //  dtostrf(val, width, precision, buffer);

    Serial.begin(115200);
    double dVal = 123.4567;
    char buffer[10];
    dtostrf(dVal, 5, 2, buffer);  // Prints "123.46"
    Serial.println(buffer);

    dtostrf(dVal, 4, 2, buffer);  // Prints "123.46"
    Serial.println(buffer);

    dtostrf(dVal, 0, 3, buffer);  // Prints "123.457"
    Serial.println(buffer);

    dtostrf(dVal, 6, 2, buffer);  // Prints "123.46"
    Serial.println(buffer);

    dtostrf(dVal, 7, 2, buffer);  // Prints " 123.46"
    Serial.println(buffer);

    dVal=0.12345;
    dtostrf(dVal, 0, 2, buffer);  // Prints "0.12"
    Serial.println(buffer);
}

void loop(){}

N.B. Don't bother trying with 'sprintf()', either. 'float' variables aren't supported in Arduino with 'sprintf()'. It just results in '?'. :frowning:

Edit: Here's a link to the AVR Libc documentation:-
Conversion functions for double arguments.

You can use the Xfloat widget and send the value in the same way as number, but you need to change the parameters “vvs0” and “vvs1” on nextion editor, so the widget adjust the value. For example if you wanna show the value 2.53, multiply it by 100 and then set the parameter “vvs0” to 1 and “vvs1” to 2.

Hi, Ihwan!
Can you please give me an example of a “xFloat Widget” aplication? I haven’t found any documentation about Nextion Objects Declaration… their forum seems to be closed.

Thanks.