user45654: is it even possible to print a variable output with 4 digits before and one digit after decimal in serial monitor?
my pot reading is shown in the above output
value   -   1.2
value   -   51.5
value   -   61.8
value   -   546.6
value   -   255.0
value   -   1235.9

to this
value   -   0001.2
value   -   0051.5
value   -   0061.8
value   -   0546.6
value   -   0255.0
value   -   1235.9


user33871: if(val < 1000){Serial.print('0');}
if(val < 100){Serial.print('0');}
if(val < 10){Serial.print('0');}
Serial.println(val, 1);


user30175: You basiscally want a format string which includes %f. However on Arduino, that only returns a ? (not included to to space reasons). Refer to https://stackoverflow.com/q/27651012/5296568.
However the alternative is dtostrf (double-to-string-formatted). The function takes the double / float value, the total wanted width of the string and the decimal places you want to have.
However it fills the string with spaces to the left until the total width is met. You need an additional pass to replace it with 0.
#include <Arduino.h>

void setup(){
    Serial.begin(115200);

    const float vals[] = {
            1.2, 51.5, 61.8,
            546.6, 255.0,
            1235.9
    };

    //allocate 8 byte buffer
    //biggest string is "-9999.9\0" (with NUL)
    char buf[8];

    int numVals = (int) (sizeof(vals) / sizeof(*vals));

    for(int i=0; i < numVals; i++) {
        //format correctly
        dtostrf(vals[i], 4+1+1, 1, buf);

        //convert left-appended spaces to zeroes
        for(size_t j=0; j < sizeof(buf); j++){
            if(buf[j] == ' ')
                buf[j] = '0';
        }

        //print buffer
        Serial.println(buf);
    }
}


void loop() {
}

Prints
0001.2
0051.5
0061.8
0546.6
0255.0
1235.9

Edit: You can also offload it into a function and then feed it with the ADC values.
Example:
#include <Arduino.h>

void printValueFormatted(float value, int numDecimalPlaces, int totalWidth) {
    //format correctly
    char buf[16]; 
    //prevent buffer overflow
    if(totalWidth >= (int) sizeof(buf))
         return;
    dtostrf(value, totalWidth, numDecimalPlaces, buf);

    //convert left-appended spaces to zeroes
    for(size_t j=0; j < sizeof(buf); j++){
        if(buf[j] == ' ')
            buf[j] = '0';
    }

    //print buffer without newline
    Serial.print(buf);
}

void setup(){
    Serial.begin(115200);
}


void loop() {
    float val = analogRead(0);
    Serial.print("ADC Count: ");
    Serial.print(val);
    Serial.print("  -- Voltage: ");
    val = val * 5.0f / 1023.0f;
    printValueFormatted(val, 1, 4+1+1);
    //print newline
    Serial.println();
    delay(100);
}

Prints
ADC Count: 719.00  -- Voltage: 0003.5
ADC Count: 718.00  -- Voltage: 0003.5


45654: <p>is it even possible to print a variable output with 4 digits before and one digit after decimal in serial monitor?</p>

<p>my pot reading is shown in the above output</p>

<pre><code>value   -   1.2
value   -   51.5
value   -   61.8
value   -   546.6
value   -   255.0
value   -   1235.9
</code></pre>

<p>to this</p>

<pre><code>value   -   0001.2
value   -   0051.5
value   -   0061.8
value   -   0546.6
value   -   0255.0
value   -   1235.9
</code></pre>
 33871: <pre><code>if(val &lt; 1000){Serial.print('0');}
if(val &lt; 100){Serial.print('0');}
if(val &lt; 10){Serial.print('0');}
Serial.println(val, 1);
</code></pre>
 30175: <p>You basiscally want a format string which includes <code>%f</code>. However on Arduino, that only returns a <code>?</code> (not included to to space reasons). Refer to <a href="https://stackoverflow.com/q/27651012/5296568">https://stackoverflow.com/q/27651012/5296568</a>.</p>

<p>However the alternative is <code>dtostrf</code> (<a href="https://www.microchip.com/webdoc/AVRLibcReferenceManual/group__avr__stdlib_1ga060c998e77fb5fc0d3168b3ce8771d42.html" rel="nofollow noreferrer">double-to-string-formatted</a>). The function takes the <code>double</code> / <code>float</code> value, the total wanted width of the string and the decimal places you want to have.</p>

<p>However it fills the string with spaces to the left until the total width is met. You need an additional pass to replace it with <code>0</code>.</p>

<pre><code>#include &lt;Arduino.h&gt;

void setup(){
    Serial.begin(115200);

    const float vals[] = {
            1.2, 51.5, 61.8,
            546.6, 255.0,
            1235.9
    };

    //allocate 8 byte buffer
    //biggest string is "-9999.9\0" (with NUL)
    char buf[8];

    int numVals = (int) (sizeof(vals) / sizeof(*vals));

    for(int i=0; i &lt; numVals; i++) {
        //format correctly
        dtostrf(vals[i], 4+1+1, 1, buf);

        //convert left-appended spaces to zeroes
        for(size_t j=0; j &lt; sizeof(buf); j++){
            if(buf[j] == ' ')
                buf[j] = '0';
        }

        //print buffer
        Serial.println(buf);
    }
}


void loop() {
}
</code></pre>

<p>Prints</p>

<pre><code>0001.2
0051.5
0061.8
0546.6
0255.0
1235.9
</code></pre>

<p>Edit: You can also offload it into a function and then feed it with the ADC values.</p>

<p>Example:</p>

<pre><code>#include &lt;Arduino.h&gt;

void printValueFormatted(float value, int numDecimalPlaces, int totalWidth) {
    //format correctly
    char buf[16]; 
    //prevent buffer overflow
    if(totalWidth &gt;= (int) sizeof(buf))
         return;
    dtostrf(value, totalWidth, numDecimalPlaces, buf);

    //convert left-appended spaces to zeroes
    for(size_t j=0; j &lt; sizeof(buf); j++){
        if(buf[j] == ' ')
            buf[j] = '0';
    }

    //print buffer without newline
    Serial.print(buf);
}

void setup(){
    Serial.begin(115200);
}


void loop() {
    float val = analogRead(0);
    Serial.print("ADC Count: ");
    Serial.print(val);
    Serial.print("  -- Voltage: ");
    val = val * 5.0f / 1023.0f;
    printValueFormatted(val, 1, 4+1+1);
    //print newline
    Serial.println();
    delay(100);
}
</code></pre>

<p>Prints</p>

<pre><code>ADC Count: 719.00  -- Voltage: 0003.5
ADC Count: 718.00  -- Voltage: 0003.5
</code></pre>
