# From floating value 0.022 to 22 for serial communication

Hi, although I looked in the forums but I did not came to a solution which in the end would be simple if you know the solution. ;D
Can I get this double converted to a string? Or is this the wrong way?

My VB6 PC application accepts numbers upto 999999 by serial commmunication but no fractionals so fractionals need to be converted before send to serial.
So a value like 0.022 in the serial monitor which is for the Amps value needs to become 22 which is miliAmps.
How can I get this 22 and not 22.00 to send to serial.

``````/*
Measuring Current Using ACS712 30A Module
*/
//int mVperAmp = 185; // for 20A Module
int mVperAmp = 66; // for 30A Module
int RawValue= 0;
int ACSoffset = 2500;
double Voltage = 0;
double Amps = 0;

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

void loop()
{

Voltage = (RawValue / 1023.0) * 5000; // Gets you mV
Amps = ((Voltage - ACSoffset) / mVperAmp);

Serial.print("Raw Value = " ); // shows pre-scaled value
Serial.print(RawValue);
Serial.print("\t mV = "); // shows the voltage measured
Serial.print(Voltage,3); // the '3' after voltage allows you to display 3 digits after decimal point
Serial.print("\t Amps = "); // shows the voltage measured
Serial.println(Amps,3); // the '3' after voltage allows you to display 3 digits after decimal point
delay(1000);

}
``````

long int ma = 1000.0*Amps;
Serial.println(ma);

Just cast it to an int:

``````   int sendVal;
float rawVal = 22.0;

sendVal = (int) rawVal;
``````

If the value is always less than a whole number, you can always figure out the decimal place and multiply by a power of 10 and cast that to an int.

Edit: I misunderstood and thought it was always greater than 1, but with a decimal value. jremington's approach should be:

long amps = 1000 * mA;

You don't want the decimal zero since you're assigning into an long.

Thank you guys, problem solved.

Paco

You could also do it this way:

Serial.println(1000*Amps,0);