As Lamak says, the float
is an approximate data if you need to maintain a precision you should modify the type to decimal
for example a decimal(15,8)
. To complement, you have some other options. Let's see some:
This function can be configured with the parameter style
of float
a 128
CONVERT(VARCHAR, @flo, 128)
Important : Do not use this form, I only indicate it for information purposes, according to the documentation 126, 128, 129 Included for legacy reasons and might be deprecated in a future release.
You can previously "cast" the float
to decimal
with the accuracy you are looking for, for example:
CAST(CAST(@flo AS DECIMAL(15,8)) AS VARCHAR(30))
Surely this option is the best for old versions of SQL server
, it is not your case.
This function is available from version 2008
and gives better control over the representation in characters of a float
since it allows to establish length and precision:
STR(@flo, 15,8)
Of all the forms I am still staying with the proposal of Lamak since you do not add 0
to the left, example:
DECLARE @flo FLOAT = -34.6919581
SELECT CONVERT(VARCHAR, @flo, 128),
CAST(CAST(@flo AS DECIMAL(15,8)) AS VARCHAR(30)),
STR(@flo, 15,8),
FORMAT(@flo,'G')
CONVERT CAST DECIMAL STR FORMAT
------------ -------------- --------------- -----------
-34.6919581 -34.69195810 -34.69195810 -34.6919581