dtostrf rounding [SOLVED]

I was using an unsigned long to hold unixtime and I noticed my unsigned longs are being rounded by dtostrf. So are signed longs.

Anyone know what’s going on here?

void setup(){
  Serial.begin(115200);
  int32_t    lng = 1234567890;
  uint32_t unlng = 1234567890;
  char buf[20];
  Serial.print("1: ");
  Serial.println(unlng);
  Serial.print("2:");
  dtostrf(unlng,11,0,buf);
  Serial.println(buf);
  Serial.print("3: ");
  Serial.println(lng);
  Serial.print("4:");
  dtostrf(lng,11,0,buf);
  Serial.println(buf);
}


void loop(){}

Output:

1: 1234567890
2: 1234567900
3: 1234567890
4: 1234567900

dtostrf() takes a floating point argument, which is single precision on the Arduino. You are lucky to get as many correct digits as you do. Use ltoa() instead.

Thanks, I need to make a conversion cheat sheet to keep track of these.