OLED clearing screen areas

I am using a 1351 OLED and have a page switch routine that on button push moves to a new page.

In the fuel and water pages, as the numbers update from the sensor I am trying to find a function that will just clear the screen area that doesnt change.

For instance if the sensor shows 103 and then 50 I dont want the 3 (of the 103 ) to still display.

If I just fill the screen black at the start of each page it has the effect of making everything disappear and then rewrite and I only want the unused area to clear.

void changeDisplay()
{
  dispChngpinState = digitalRead(dispChngpin);

  // Serial.println (buttonPushCounter);
  if (dispChngpinState != lastdispChngState)
  {
    if (dispChngpinState == LOW)
    {
      buttonPushCounter++;
      delay(100);
    }
  }
  lastdispChngState = dispChngpinState;

  if (buttonPushCounter  == 1)
  {
    RTCNow();
  }
  if (buttonPushCounter  == 2)
  {
    tft.fillScreen(BLACK);
    buttonPushCounter = 3;
  }
  if (buttonPushCounter  == 3)
  {
    tft.setCursor(30, 5);
    tft.setTextColor(WHITE);
    tft.setTextSize(2);
    tft.println("Suzuki");
    tft.setCursor(55, 40);
    tft.setTextSize(4);
    tft.println("7");
  }
  if (buttonPushCounter  == 4)
  {
    watertemp();
    tft.setCursor(30, 5);
    tft.setTextColor(WHITE, BLACK);
    tft.setTextSize(2);
    tft.println("Temp");
    tft.setTextSize(4);
    tft.setCursor(30, 30 );
    tft.setTextColor(WHITE, BLACK); // refreshes text area
    tft.println(temperature,2);
  }
  if (buttonPushCounter  == 5)
  {
    fuelSender();
    tft.setCursor(30, 5 );
    tft.setTextColor(WHITE, BLACK);
    tft.setTextSize(2);
    tft.println("Fuel");
    tft.setTextSize(4);
    tft.setCursor(30, 30 );
    tft.setTextColor(WHITE, BLACK); // refreshes text area
    tft.println(itoa(fuel, buf5, 10));
    tft.fillScreen(BLACK);
  }
  if (buttonPushCounter  == 6)
  {
    tft.fillScreen(BLACK);
    buttonPushCounter = 1;
  }

}

The typical solution to this is to test the value you are displaying

if( val < 100 ) tft.print(" ");
if( val < 10 ) tft.print(" ");
tft.print(val);

or reverse the order of the statements if you want the value left justified.
You can also use sprintf() with a %3d specification to make it always take up 3 chars

It works well. Thankyou!

Just so that I totally understand.....

I can see that the (" ") is filling an area of the display with nothing but how does it know what area to fill?

It looks like a form of nested IF? so is it if less that 100 print a blank (else print the number) , if less than 10, print another blank, else print the number?.

Sorry bit new to managing Oleds....and programming

but how does it know what area to fill?

It doesn't, it just prints a space at the cursor position.

kpg:
It works well. Thankyou!

Just so that I totally understand.....

I can see that the (" ") is filling an area of the display with nothing but how does it know what area to fill?

It looks like a form of nested IF? so is it if less that 100 print a blank (else print the number) , if less than 10, print another blank, else print the number?.

Sorry bit new to managing Oleds....and programming

Those if statements are not nested. They are independent of each other so
if val < 100, print a space else do nothing
if val < 10, print a space else do nothing
print the number.

You could turn them into a nested if() structure, but that would just over-complicate things.