Converting float to int by removeing decimal point

I'm working on a project where I need to convert a float to an integer so that I can send it over serial.
I want to convert it so that
float 12.34
becomes
int 1234
then on the other end, I can just divide
int 1234 by 100
and get
float 12.34

Hi, @the555timer
Welcome to the forum.
Multiply the number by 100 .
Then turn it into an int before sending.

Tom... :grinning: :+1: :coffee: :australia:

Why do you want to do this? Why not just send "12.34"? What device is sending the data? What device is receiving it?

an Arduino nano is sending the data and an Uno is receiving it

I've tried it but the data i receive is always zero

Hi,
Show us your code?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

Why are you using two Arduino in your project?

Is Uno reading zero because the Nano is sending zero? Have you examined what the Nano is sending on serial monitor?

I'm building a cable length meter and I want to have a detachable screen

the nano is sending the correct numbers

Let's see the Uno code. There should be no problem reading a value with decimal places.

code on the nano

#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
#include <Wire.h>
float cntr = 0.00;
int devider;
int latch = HIGH;
int button1;
int button2;
float meters;
float timer1;
char voltBuff[7];
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void countup()
{
  cntr++;
  delayMicroseconds(50);
}

void setup()
{
  lcd.init();
  devider = EEPROM.read(1);
  Serial.begin(9600); // initialize the lcd
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT_PULLUP);
  pinMode(A2, INPUT_PULLUP);
  pinMode(A3, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(2), countup, FALLING);
  lcd.backlight();
  lcd.setCursor(4, 0);
  lcd.print("CLM V2.6");
  lcd.setCursor(4, 1);
  lcd.print("SZFT KFT");
  delay(1000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("DEVIDER:");
  lcd.print(devider);
  delay(1000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("LENGHT:");
  lcd.print(0.00);
  lcd.print("M");
}
void send_float (float arg)
{
  Serial.write(int(arg * 100));
}
void setdevider()
{
  latch = LOW;
  Serial.begin(9600);
  lcd.setCursor(0, 0);
  lcd.print("DEVIDER:");
  lcd.print(devider);
  lcd.print(" ");
  lcd.setCursor(0, 1);
  lcd.print("PULSES:");
  lcd.print(cntr / 4);
  if (button1 == LOW)
  {
    devider++;
    delay(200);
  }
  if (button2 == LOW)
  {
    devider--;
    delay(200);
  }
  if (digitalRead(4) == LOW)
  {
    EEPROM.write(1, devider);
    latch = HIGH;
    cntr = 0;
    timer1 = 0;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("LENGHT:");
    lcd.print(0.00);
    lcd.print("M");
  }
}
void loop()
{
  button1 = digitalRead(A2);
  button2 = digitalRead(A3);
  if ((button1 == LOW or button2 == LOW) & latch == HIGH)
    cntr = 0;
  if (button1 == LOW or button2 == LOW or latch == LOW)
    setdevider();
  else
  {
    if (digitalRead(4) == LOW)
    {
      cntr = 0;
      timer1 = 0;
      lcd.setCursor(0, 0);
      lcd.print("LENGHT:");
      lcd.print(0.00);
      lcd.print("M");
    }
    if (timer1 + 0.01 < cntr)
    {
      meters = cntr / (devider * 4);
      lcd.setCursor(7, 0);
      lcd.print(meters);
      lcd.print("M");
      timer1 = cntr;
      send_float(meters);
    }
  }
}

code on the uno

#include <Arduino.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
Adafruit_PCD8544 display = Adafruit_PCD8544(5, 2, 4, 6, 3);
unsigned long timer1;
void setup()
{
  display.begin();
  display.setContrast(255);
  display.display();
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(BLACK);
  display.setCursor(15, 10);
  display.println("CLMK V1.4");
  display.setCursor(20, 20);
  display.println("SZFT.EU");
  display.display();
  delay(1000);
  display.clearDisplay();
  display.display();
  Serial.begin(9600);
}
void writedata()
{
}

void loop()
{
  if (timer1 + 100 < millis())
  {
    timer1 = millis();
    display.clearDisplay();
    display.display();
    display.setCursor(0, 0);
    display.println(Serial.read());
    Serial.println((Serial.read() + 1)/100);

    display.display();
  }
}

Here's your problem

Serial.read()

That reads one single ASCII character, if there is one that had been received. If not, it does not wait, just returns zero.

Try

Serial.parseInt()

Also, with these two lines

    display.println(Serial.read());
    Serial.println((Serial.read() + 1)/100);

You are reading ascii 2 characters, if two are available, so what is printed on the display could be different to what is displayed on serial monitor. Using Serial.parseInt(), read the value once only into a variable, then print the variable to the display and serial monitor.

with
Serial.parseInt() it just doesnt work at all

You can send float using UART Port.

float x = 12.34;
Serial.println(x, 2);  //two digits after decimal point; 6 ASCII bytes are transmitted 

Receive and retrieve float:

char myData[5] = "";
float x = atof(myData); //populate myData array with received ASCII codes of 12.34
Serial.println(x, 2); //shows: 12.34

This only sends binary values from 0 to 255. If 'arg' is greater than 2.55 you will lose data. I recommend you change this to:
Serial.println(arg);
and on the receiver side, use:

  float value = Serial.parseFloat();
  if (value != 0.0)
  {
      display.println(value);
      Serial.println(value);
  }

so I managed to make a kind of working sketch from GolamMostafa's sending float example
and johnwasser's receive examples and most of the time I get the right values printed on the screen but sometimes the number jumps to a really high number then comes back to normal.
now I'm wondering if it is because the serial connection is not stable enough or if it's something with my code...

Please, post your codes.