Serial.print for floating numbers

A simpler way to display a floating point value with three decimal places is to specify the number of decimal places in .print().

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

void loop() {
  int rawcurr = analogRead(A0);
  float current = (516 - rawcurr) * 45 / 1023.0;

  Serial.print(current, 3);
  Serial.print(" , ");
  Serial.println(rawcurr);

  delay(500);
}
2 Likes