float to binary ?

Hi,
Why does this function round and how do you return the same number without rounding
A=0.569546;
B = float2bin(A)
C=bin2float(B)
result: c= 0.5695

回答(2 个)

Jan
Jan 2021-3-8
编辑:Jan 2021-3-8
Are you sure that there is a rounding? Or is it the display in the command window only?
A = 0.569546;
B = float2bin(A)
C = bin2float(B)
A - C
format long g % Adjust the format of the display
C
float2bin and bin2float are no commands of Matlab's toolboxes. So maybe it would help to mention, where you ot these functions from.
Assuming that you are using this File Exchange entry, it doesn't round. The issue is that the default MATLAB display format only shows the first 4 figures. Try this instead:
format long
A=0.569546;
B = float2bin(A)
C=bin2float(B)

类别

标签

提问:

2021-3-8

编辑:

Jan
2021-3-8

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by