1.06 is not a float. The closest float is 1.059999942779541015625. If you multiply that by 100 you get a number that, again, is not a float. Rounding to the nearest float yields 105.99999237060546875, which is the result of the expression ver * 100, and just one ULP short of 106. Yes, floating point computations do quite usually involve rounding steps.

Casting to an int implicitly rounds towards zero, and you get 105, which is the correct result. Correct according to the rules of IEEE 754 arithmetics.

You may want to round() to the nearest integer before the cast.

Variable ver can be any decimal in this format x.xx

No, a float cannot be “any decimal” in this format. Floats are stored in binary, and most decimal numbers (numbers that can be written with a finite number of decimal digits) cannot be written in binary with a finite number of bits.

Except for a few values (namely the multiples of 0.25), ver can only store an approximation of the decimal number.

Answer from Edgar Bonet on Stack Exchange
🌐
Arduino Forum
forum.arduino.cc › projects › programming
converting a float to integer - Programming - Arduino Forum
August 26, 2017 - Is it possible to write a function that gets float values and convert them to integers?
🌐
Arduino Forum
forum.arduino.cc › projects › programming
How to actually convert float to int? - Programming - Arduino Forum
October 28, 2023 - int(float) returns wildly wrong values... I get that this is some kind of conversion error to be expected, I'm working with a float like 12345.67 and it comes out to weird numbers. ...but I really need to get an int fro…
Discussions

Converting float to int
Hi guys, Im building an android program in processing and I need some help. I would of postid this in the processing forum but it should be an easy question and nobody is there?!!? Also processing language is very simil… More on forum.arduino.cc
🌐 forum.arduino.cc
0
0
January 25, 2012
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 More on forum.arduino.cc
🌐 forum.arduino.cc
0
0
December 10, 2021
Convert float to int error - Arduino Stack Exchange
I am trying to convert 1.06 to 106 by multiplying by 100 but the answer comes 105, I do not know why. Variable ver can be any decimal in this format x.xx float ver = 1.06; int vers = ver * 100; vm[... More on arduino.stackexchange.com
🌐 arduino.stackexchange.com
September 30, 2021
arduino - C embedded convert float to int - Stack Overflow
Hello I am trying get to work a simple 5hz led via interrupt on an arduino. I want to calculate how many Timer overflows have to occure before I have to toggle my leds. However I cant compute the v... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Convert float to Int - Programming - Arduino Forum
February 1, 2021 - I have a variable called maxVoltage, say maxVoltage = 1.95. How can i convert this to 195, in essence i want to "remove" the decimal point. If i multiply by 100 int maxVoltageInt = maxVoltage * 100; Serial.print("max Volage is now: "); Serial.println(maxVoltageInt); I get 196 in the output
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Converting float to int - Programming - Arduino Forum
January 25, 2012 - Hi guys, Im building an android program in processing and I need some help. I would of postid this in the processing forum but it should be an easy question and nobody is there?!!? Also processing language is very simil…
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Converting float to int by removeing decimal point - Programming - Arduino Forum
December 10, 2021 - 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 …
Find elsewhere
🌐
Arduino
arduino.cc › reference › en › language › variables › data-types › float
float | Arduino Documentation
May 15, 2024 - Arduino programming language can be divided in three main parts: functions, values (variables and constants), and structure · For controlling the Arduino board and performing computations
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Float-to- int failure - puzzlement! - Programming - Arduino Forum
September 6, 2023 - Hi all. I am using Arduino IDE and ESP32. The code below is showing an incorrect result in the last Print statement. I suspect it is the conversion from float to int the problem. Please can you see why is this happening? Regards float Vin = 1; void setup() { Serial.begin(9600); print_int(); } void print_int() { Vin = Vin * 0.1; //Here Vin=0.1 int int_1 = Vin * 1000; Vin = Vin * 0.1; //Here Vin=0.01 int int_2 = Vin * 1000; Vin = Vin * 0.1; //Here Vin=0...
🌐
TutorialsPoint
tutorialspoint.com › convert-string-to-integer-float-in-arduino
Convert string to integer/ float in Arduino
March 24, 2021 - void setup() { Serial.begin(9600); Serial.println(); // put your setup code here, to run once: String s1 = "235"; String s2 = "1.56"; String s3 = "Hello"; int i1 = s1.toInt(); int i2 = s2.toInt(); int i3 = s3.toInt(); float f1 = s2.toFloat(); float f2 = s3.toFloat(); Serial.println(i1); Serial.println(i2); Serial.println(i3); Serial.println(f1); Serial.println(f2); } void loop() { // put your main code here, to run repeatedly: } ... As you can see, the integer and float conversions for "Hello" are 0.
🌐
GitHub
github.com › arduino › Arduino › issues › 8751
Converting float to int · Issue #8751 · arduino/Arduino
April 4, 2019 - float answer = 0.0; float i = 0.0; void setup() { Serial.begin(115200); Serial.println("Hello World !!!"); } void loop() { while(true) { answer = pow(5.0, i); Serial.print("Answer: "); Serial.println(answer); if (i >= 4.0){i = 0.0;}; //preventing overflow int b = static_cast<int>(answer);//converting to int Serial.print("B: "); Serial.println(b); delay(500); i += 1.0; } }
Author   mariusvds
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Convert Float to Int Problem - Programming - Arduino Forum
January 7, 2021 - Hello, I've checked various posts like this on the forum to no success so I'm looking for a fresh start. Essentially, I multiplied two floats successfully then just need them to convert into an int so I can put them into the stepper function. But the resulting integer flips it negativity and changes the value. distX=14.00 stepX=-29976 stepXfloat=35560.00 speedX=600 Beep Boop The "stepXfloat is the desired value and "stepX" is the int result.
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Transform int to float - Programming - Arduino Forum
February 3, 2018 - Hi, I would like to transform an int to a float but changing the decimal points. Example: int a=1235; float x=0; I would like to store a on x such that I have x=12.35; I won't explain why i need to do something lik…
🌐
Arduino Forum
forum.arduino.cc › projects › programming
float vs integer - Programming - Arduino Forum
March 16, 2017 - what is the result of "float"/"integer"? A float or an integer? What, if the second is true, should I do to obtain a float while the divisor is a variable "int x = 8"?
🌐
Arduino Forum
forum.arduino.cc › forum 2005-2010 (read only) › international › deutsch
float in int umwandeln - Deutsch - Arduino Forum
May 28, 2010 - Hallo, wie kann ich ein float in ein int umwandeln? Oder wie kann ich eine Kommazahl in eine Ganzzahl auf oder abrunden. Ich habe schon im Forum gesucht, konnte aber nicht das Richtig finden. Erschwerend kommt hinzu d…
🌐
Arduino Forum
forum.arduino.cc › projects › programming
[FIXED] Problem converting float to int - Programming - Arduino Forum
March 25, 2016 - Hello, I am working on a project, where I get an imput from a force sensitive resistor and want to convert "float force" into "int b" to farther use b in my programm. I am using SEN-09376. This is what I have atm: float force; int b=(int)force; const int FSR_PIN = A0; const float VCC = 4.98; const float R_DIV = 3230.0; void setup (){ Serial.begin(9600); pinMode(FSR_PIN, INPUT); } void loop() { int fsrADC = analogRead(FSR_PIN); if (fsrADC != 0) { float fsrV = fsrADC * VCC ...
🌐
Arduino Forum
forum.arduino.cc › forum 2005-2010 (read only) › software › syntax & programs
Casting Float to Int - Syntax & Programs - Arduino Forum
July 22, 2010 - Hello all, Been playing around with formating float to a string for my specific needs but encountered a problem. Here is the complete sketch I am testing with: #include // Include the Streaming library #include 0 ) value += 0.5/(float)100; el...
🌐
Arduino Forum
forum.arduino.cc › projects › general guidance
Converting Float to Int - General Guidance - Arduino Forum
January 30, 2013 - Hey forum, Im building a gps reciever. I allready recieve coordinates, but I want to display these coordinates on an PCD8544 lcd screen. I recieve the coordinates as a float, example: flat=51.96512; This coordinate…
🌐
Arduino Forum
forum.arduino.cc › projects › programming
CAST float to int unexpected results - Programming - Arduino Forum
February 24, 2018 - I've been getting unexpected results when trying to convert a FLOAT to an INT. int recastVar = (int)newDouble; In my script when my double = 8.0, the recast int value returned is 7. The script below illustrates the pro…