Using Sybase ASE 12.5 I have the following situation.
2 values stored in float cols when multiplied give a value.
Converting that value to a varchar (or retrieving it with Java) gives the underlying precise value which the floats approximated to.
My issue is that the value as represented by the floats is correct, but the precise value is causing issues (due to strict rounding rules).
For example
declare @a float,@b float
select @a = 4.047000, @b = 1033000.000000
select @a*@b as correct , str(@a*@b,40,20) as wrong
gives:
correct: 4180551.000000,
wrong: 4180550.9999999995343387
Similarly when @a = 4.047000, @b = 1 ...you get
correct: 4.047000,
wrong: 4.0469999999999997
(same thing happens using convert(varchar(30), @a*@b) and cast(@a*@b, varchar(30) )
I appreciate it would be easy to just round the first example in java but for various business reasons that cannot be done and in any case it wouldn't work for the second.
I also cannot change the float table column datatype.
Is there anyway to get the float representation of the multiplication product either as a string or the actual 'correct' value above?
Thanks Chris