sql - Why does Sybase ASE throw a truncation error in a division followed by a subtraction? -


i using sybase ase 15. in following sql, there truncation error, if division of 2 numbers followed subtraction.

    declare @p1  decimal (30,16)     declare @p2  decimal (30,16)     select @p1 = 0.0000504412630951  --sixteen decimal places     select @p2 = 0.0000512178647912     select 'this succeeds:'     select @p1, @p2, (@p1 / @p2)          --this succeeds: displays values     select 'this fails:'     select @p1, @p2, (@p1 / @p2)  - 1.0  --this fails truncation error.  why?     select 'why succeed?'     select @p1, @p2, round( (@p1 / @p2), 46 )  - 1.0  --this succeeds 46 or less, fails 47 or greater - why? 

thanks in advance.

bob

the 1.0 not decimal datatype @p1 , @p2 , it's created float since not specify precision , scale (or cast numeric/decimal data type). first attempt succeeds because there no implicit conversion, you're dividing 2 decimals same precision/scale. 2nd attempt fails because subtracting 1.0 subtracting float value of 1.0 against decimal forces implicit conversion decimal. since implied , not explicit, truncation error because system wants know losing scale doing given operation. round function in 3rd attempt doing explicit conversion, truncation ignored because telling system want out of operation.

you can find more information on scale error @ link below, how turn off if don't care (look towards bottom of page).

sybooks online - conversion error handling


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -