# Tag Info

Accepted

### How do I convert a float into char*?

There is a function in the standard Arduino library called dtostrf(). I think of it as "Decimal to String Float". You pass in the float, how wide you want the whole number to be (if it will fit), the ...
• 1,875
Accepted

### Only 2 decimal places in printed float

By default, the Serial print function shows only 2 decimals, however I'm sure the float has the full (unrounded) value, even if it does not show it. You can read about it in the official ...
Accepted

### Serial monitor can't display float and double values with absolute greater than 4294967040=2^32-2^8

It's not the data type, it's the printing routine that sets that limit. In Print.cpp: 227 if (isnan(number)) return print("nan"); 228 if (isinf(number)) return print("inf"); ...
• 105k

### Only 2 decimal places in printed float

By default, Serial.print() prints floats with two decimal digits. float num = 7.875; Serial.println(num, 4); will print num with 4 decimal digits, thus: 7.8750. The precision of float is not ...
• 375
Accepted

### Will an ATmega2560 board be faster than a Uno for hard real-time data logging?

No, it will not be any faster. The extra instructions are to access the extra flash memory of the 2560. Instructions like EIJMP - Extended indirect jump, EICALL - Extended indirect call, etc. The ...
• 105k
Accepted

### Is there a non-float alternative to pow()?

For the general case, @dat_ha 's answer is correct, but it is worth noting that you want a very special case... powers of two. Because computers use binary arithmetic, operations involving powers of ...
• 206
Accepted

### Print with round towards zero instead of round to nearest

A cheap trick to round a number to one decimal place (in "chop-off mode") is to multiply it by 10, convert it to an integer, and divide by 10.0f again: float myVal = 123.89f; myVal = (long)(myVal * ...
• 3,646

### Converting from Float to Int yielding weird results. What am I doing wrong?

On an Arduino board with the 328 processor, an INT is stored as a 2 byte value, so the max number is 32,767. You want to use a LONG which is a 4 byte number which has a max of 2,147,483,647. When the ...
• 630

### Will an ATmega2560 board be faster than a Uno for hard real-time data logging?

Use the newest Arduino IDE, because some time ago the 'lto' option was added which is a major optimization for both speed and size. It is possible to test a few compiler options with the #pragma. Try ...
• 3,246
Accepted

### Convert float to byte, from Arduino to Raspberry Pi i2c

First of all, if you want the Arduino to send data as a slave, it should do so onRequest(), not onReceive(). Thus: void setup() { Wire.begin(0x08); Wire.onRequest(handleRequest); } Next, as ...
• 43.3k
Accepted

### Convert float to int error

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, ...
• 43.3k
Accepted

### Avoiding float math to speed up arduino

What you are asking for is not simple, especially since you have this power function that can be hard to approximate. First, you have to figure out the range and the required precision of each of the ...
• 43.3k

### When is it necessary to use "float" instead of "int"?

An integer is a whole or natural number. Computers use integers for counting and comparisons. Computers can count precisely using integers and comparisons of two integers can be absolutely true or ...
• 7,350

### Floating-point without FPU

As I said in my comment, all float operations are implemented in software. As a simple test, I compiled the following program: volatile float x, y, z; int main(void) { z = x + y; return 0; } ...
• 43.3k
Accepted

### Make a float using integers

Seems too simple: float x = n1 + n2 * 0.1; Is there a trick? Edit: The method proposed by Michel Keijzers, namely float x = n1 + n2 / 10.0; (I removed the redundant casts) can be slightly more ...
• 43.3k

### All floats feedback a rounded down integer

You already got a couple of perfectly good answer. I will nevertheless suggest a slightly different idiom: float voltage = sensorVal * (5.0 / 1024); or, maybe better: const float V_REF = 5.0; // ...
• 43.3k

### Will an ATmega2560 board be faster than a Uno for hard real-time data logging?

In the platform.txt file found in ~/Arduino15/packages/arduino/hardware/avr/1.6.17 or similar, you can change the three instances of -Os with -Ofast. The size of the code can increase dramatically ...
• 1,588
Accepted

### build fixed size strings from floats

The simple way would be to format the string with sprintf - however sprintf on the Arduino lacks floating point support (although it is possible to enable it). So if you convert your floating point ...
• 105k

### When is it necessary to use "float" instead of "int"?

"int" means integer. It's either one whole number (forgive me, mathematicians, for the sloppy definition!) or the next or previous. A "float" is a floating-point number - that is, a number and part ...
• 6,974

### Assigning float to 10 decimal place for longitude,latitude

But when after setting the Longitude and Latitude to float.When I use this code, I don't get a valid gps data. Some statements in C/C++ are not what they might seem. The value of the statements: ...
• 7,979

### float precision in arduino

Just write the amount of numbers you want to get float here Serial.println(val); after the val. example: Serial.println(val, 5); It will give 5 digits after the decimal point
• 31

### Arduino not adding decimals correctly on double variable

The 8 bit Arduinos don't have precision, or anything even close to precision when it comes to working with decimal values. There is no such thing as double on an 8-bit Arduino - it is only an alias ...
• 105k
Accepted

### How to use a coma as the decimal separator?

Print the integer part, print a comma, then print the value minus the integer part. float value = 123.45; int ival = (int)value; int frac = (value - ival) * 100; Serial.print(ival); Serial.print(",")...
• 105k

### Is the strange problem I'm having to do with comparing floats?

You already know, from previous answers, why the comparison doesn't give you the result you expect: you assumed that any multiple of 0.1 is also a multiple of 0.001, which is true for real numbers but ...
• 43.3k

### Two floating point values do not get added and printed on ESP-WROOM-32

Try doubles instead of floats. Your initial value, 34567891.234 needs 35 bits of precision to keep track of the decimals, but floats only have 24 bits pf precision. So to have enough precision to ...
• 2,332
Accepted

### How to write a float value EEPROM

You have multiple options: According to jsotola's remark: the easiest is to multiply your value by 2, store it, and after reading, divide it by 2. In one byte you can store a value from 0 to 127.5 (...
Accepted

### Cannot understand why this code work but this not

Your problem is that you are doing integer maths. mr = (130-20)/(1023-205) reduces to: mr = 110/818 Which normally equates to: mr = 0.135 But since all those numbers are integers the result is ...
• 105k
Accepted

### Enable full float-capable snprintf() library with PlatformIO

I finally found the answer at https://github.com/sstaub/LCDi2c When using PlatformIO, add the following line to platformio.ini to enable full support for floats to printf(): build_flags = -Wl,-u,...
• 551
Accepted

### Why does the data I send to the server get rounded off and how do I send the entire float instead?

The constructor for the String object from float is this: String(double, unsigned char decimalPlaces=2); So if you don't want to have 2 decimal digits, you have to use String(someFloat, 3). Also you ...
• 4,752