Which way that allow to me store fractional number with 4 digits after point (for example 13.6925) ?
Maria88:
I just tried to use "Float" , but it stores only two digits after point .
Incorrect. It stores a lot more than two digits. You're likely only seeing two digits because that is the default number of digits printed by the stream class.
See here: Serial.print() - Arduino Reference
An optional second parameter specifies the base (format) to use; permitted values are BIN (binary, or base 2), OCT (octal, or base 8 ), DEC (decimal, or base 10), HEX (hexadecimal, or base 16). For floating point numbers, this parameter specifies the number of decimal places to use. For example:
SYNTAX: Serial.println(X.[XXXXXXX], 7); =>" X.XXXXXXX"
thanks a lot , i know that float store more digits , but i want to store only four digits after point
Maria88:
but i want to store only four digits after point
Multiply it by 10^4 and store it in an int or a long.
Depending on what you're doing with it, though, you may just be wasting your time.
use this:
Serial.println(myFloat, 4);
floats are 4 bytes and 6-7 decimal digits of precision. the trailing digits are always there, you are just displaying the 4 (in this example) most significant ones.
but i want to store only four digits after point
How hard is it to get from this:
SYNTAX: Serial.println(X.[XXXXXXX], 7); =>" X.XXXXXXX"
to this:
SYNTAX: Serial.println(X.[XXXXXXX], n); =>" X.XXXXXXX"
to this:
Serial.println(myFloat, 4);
??
raschemmel:
How hard is it to get from this:to this:
![]()
]
:0
]
:
Ha , ha , ha, ![]()