Character Array Needs to Trim Decimal Point

The code below updates an IoT shadow with a fluid volume level. The code is working fine as long as the volume level is 1000 or higher. If it is a three digit value, the float_buf is storing the number with a trailing decimal point (ex. 879. ). This is invalid JSON structure and the IoT update is then failing.

My question is how can I trim the trailing decimal point so that if the value in the character array is four places it is stored properly (ex. 4234) and if it is 3 places it also is stored properly (ex. 879)?

char JSON_buf[100];
char float_buf[5];

float volume = resistanceToVolume(resistance, ZERO_VOLUME_RESISTANCE, CALIBRATION_RESISTANCE, CALIBRATION_VOLUME);
  Serial.print("Calculated volume: ");
  Serial.println(volume, 5);
  if (volume < 1000){
     level = "Low";
     Serial.print("Level: ");
     Serial.println(level);
  }

dtostrf(volume, 4, 1, float_buf);
  float_buf[4] = '\0';
  sprintf(JSON_buf, "{\"state\":{\"reported\":{\"Volume\":%s}}}", float_buf);
    print_log("shadow update", myClient.shadow_update(AWS_IOT_MY_THING_NAME, JSON_buf, strlen(JSON_buf), NULL, 5));
    Serial.println(JSON_buf);

Here is an example of the invalid JSON caused by the character array storing three digits and a decimal for float_buf:

Resistance: 1740.72 ohms
Calculated volume: 879.70220
Level: Low
[ERR] command: shadow update code: -31
{"state":{"reported":{"Volume":879.}}}

This is an example of valid JSON:

Resistance: 1677.81 ohms
Calculated volume: 1062.18237
[LOG] command: shadow update completed.
{"state":{"reported":{"Volume":1062}}}

If you don't want a decimal point in the output then why is volume a float ?

A fluid sensor is sending a decimal value to the Arduino board (ex. 1062.18237), but I only need to send a whole number through the JSON for IoT update (ex. 1062). The decimal values are not going to be used once sent through to the cloud.

but I only need to send a whole number through the JSON for IoT update (ex. 1062)

So copy it to an int first. Try this

void setup()
{
  Serial.begin(115200);
  float aFloat;
  int anInt;
  aFloat = 1062.18237;
  anInt = aFloat;
  Serial.println(anInt);
  aFloat = 123.4567;
  anInt = aFloat;
  Serial.println(anInt);
}

void loop()
{
}

So I have the float variable volume copying to an integer:

anInt = volume;
Serial.println(anInt);

But then the integer needs copied to character array for the JSON document:

dtostrf(volume, 4, 1, float_buf);
  float_buf[4] = '\0';
  sprintf(JSON_buf, "{\"state\":{\"reported\":{\"Volume\":%s}}}", float_buf);
    print_log("shadow update", myClient.shadow_update(AWS_IOT_MY_THING_NAME, JSON_buf, strlen(JSON_buf), NULL, 5));
    Serial.println(JSON_buf);

dtrostrf() is used to copy float to char array. Whats the best way to copy an int to a character array?

the best way to copy an int to a character array?

The appropriate verb to use is "format", not "copy", because the process is an active one that converts representations, often with additional parameters.

itoa(), ltoa(), sprintf()

itoa seems to be working for this situation.

Thanks for your help!

Steve