Rounding float to 1 dec place & concat string

My oled doesn't give me much room, so I am trying to get my voltage reading to 1 place after the decimal, and adding "v" as a string after it (without a space between the number and v).

I have spent hours trying rounding, truncating, using multipliers, int, double, float, string, etc. and I can't get anything to work.

    float Vs = 0.0;
    float input_volt = 0.0;
    float temp = 0.0;
    float r1=9880.0;     
    float r2=78000.0;  
    String stringOne;

    int analogvalue = analogRead(A2);
    temp = (analogvalue * 5) / 1024.0;       
    input_volt = temp / (r2/(r1+r2));
    Vs = input_volt * 10.0;      //this gets me back to the correct voltage when over 5v, say 12v

    stringOne = "v";

    //u8g2.print(Vs+stringOne);
    //u8g2.print(Vs,1)+stringOne ;

I either get say, 4.95v, or 5v, etc. when I want 4.9v or 5.0v (either is accurate enough).
I want the 'v' to immediately follow the .x i.e. 12.6v

I can't get it to work. I have read and tried many suggested approaches in threads, but no luck. Can someone help me ?

    u8g2.print(Vs+0.05, 1);  // Display the voltage rounded to 1 decimal place
    u8g2.print(stringOne); // add the label

Don’t get into the habit of using Strings (capital S). Especially not for a single character.

    u8g2.print(Vs, 1);  // Display the voltage rounded to 1 decimal place
    u8g2.print('V'); // add the label

(By the way, the official symbol for volts is a capital V.)

Pieter

Thank you both very much. It has been an all nighter for me, and, in looking at the solutions, I feel quite dumb. I guess I, I should have, I assumed that, I thought I tried that, stutter, stammer.

I had a feeling when I saw immediate replies that I had missed something obvious. oh well. thanks again.

pratto:
Thank you both very much. It has been an all nighter for me, and, in looking at the solutions, I feel quite dumb. I guess I, I should have, I assumed that, I thought I tried that, stutter, stammer.

Don't worry, we've all been there :slight_smile: