How to Display the right amount of significant digits??

Hi, I am doing a project. In my project, I am display on an lcd screen a number, for example 27.0
With the aid of buttons, I want to change the values of any position of the number being displayed on the screen. For example, change the 7 in 27.0 to 0, then displaying 20.0 on the screen My code works, the only problem I have is that when I turn the 2 in the 27.0 to a zero, the amount of significant digits drops by one on the display. For example, it would display 7.0, but I want it to display 07.0 (I want it to retain 3 significant digits even after the change.) My initial data type is a double.

Any help would be great. thank!

Hi, I am doing a project. In my project, I am display on an lcd screen a number, for example 27.0
With the aid of buttons, I want to change the values of any position of the number being displayed on the screen. For example, change the 7 in 27.0 to 0, then displaying 20.0 on the screen My code works, the only problem I have is that when I turn the 2 in the 27.0 to a zero, the amount of significant digits drops by one on the display. For example, it would display 7.0, but I want it to display 07.0 (I want it to retain 3 significant digits even after the change.) My initial data type is a double.

Any help would be great. thank!

Hi, I am doing a project. In my project, I am display on an lcd screen a number, for example 27.0
With the aid of buttons, I want to change the values of any position of the number being displayed on the screen. For example, change the 7 in 27.0 to 0, then displaying 20.0 on the screen My code works, the only problem I have is that when I turn the 2 in the 27.0 to a zero, the amount of significant digits drops by one on the display. For example, it would display 7.0, but I want it to display 07.0 (I want it to retain 3 significant digits even after the change.) My initial data type is a double.

Any help would be great. thank!

use char:

char chr_v[4];
int value;

void setup() {
	Serial.begin(9600);
	value = 7;
	sprintf(chr_v, "%03d", value); //%03d for 3 digits (ex: 7 -> 007)
	
	Serial.print(chr_v[0]);
	Serial.print(".");
	Serial.print(chr_v[1]);
	Serial.println(chr_v[2]);
}

void loop() {}

You can program it. Make a string from the number with dtostrf and add a '0' if needed.
Or use the sprintf(), but that is a problem... the sprintf() for the Arduino has floating point disabled, so you have to convert it to integer values.

Is it a 'float' number ?

thank!

thank!

Do not cross-post. Threads merged.