So it appears that if you
CAST(field1 as decimal) field1
this will automatically add rounding.
The original is defined as:
field1 type:float length:8 prec:53
I need to cast it to decimal, because I need my Entity Framework layer to generate this field as decimal (instead of double).
Is there a way to cast it as decimal, so that it preserves original precision, and doesn't round?
I would like to avoid having to declare the precision in the cast, because:
Have you tried:
SELECT Cast( 2.555 as decimal(53,8))
This would return 2.55500000
. Is that what you want?
UPDATE:
Apparently you can also use SQL_VARIANT_PROPERTY to find the precision and scale of a value. Example:
SELECT SQL_VARIANT_PROPERTY(Cast( 2.555 as decimal(8,7)),'Precision'), SQL_VARIANT_PROPERTY(Cast( 2.555 as decimal(8,7)),'Scale')
returns 8|7
You may be able to use this in your conversion process...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With