 Tags IOS SQL HTML C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 # SQL Server decimal division not rounding the result

By : Zack Weill
Date : August 02 2020, 02:00 AM
Hope that helps The way SQL server behaves in case of multiplication and division of decimal numbers is different, hence the difference in number of digits:
Assuming, e1=decimal(p1,s1) and e2=decimal(p2,s2) code :
``````Operation   Result precision                        Result scale *
e1 + e2     max(s1, s2) + max(p1-s1, p2-s2) + 1     max(s1, s2)
e1 - e2     max(s1, s2) + max(p1-s1, p2-s2) + 1     max(s1, s2)
e1 * e2     p1 + p2 + 1                             s1 + s2
e1 / e2     p1 - s1 + s2 + max(6, s1 + p2 + 1)      max(6, s1 + p2 + 1)
``````
``````select cast(1.225114854 as decimal(15,9))*cast(1.000000000  as decimal(15,9)) as multiply
select cast(1.225114854 as decimal(15,9))/cast(1.000000000  as decimal(15,9)) as division
``````

## Decimal rounding errors upon division (C#)

By : user3041898
Date : March 29 2020, 07:55 AM
it fixes the issue The solution is straightforward: if it hurts when you do that then don't do that.
If you have rational probabilities, that is, probabilities that are ratios of whole numbers, and you want them to add to exactly one, then don't convert them to decimal or double in the first place. Use an arbitrary-precision rational type to represent your arbitrary precision rationals.

## .Net division rounding/decimal differences between web servers

By : Randy L
Date : March 29 2020, 07:55 AM
it fixes the issue I suppose the old server was a 32bit Machine? Check http://msdn.microsoft.com/en-us/library/system.double.aspx, especially the paragrahp Floating-Point Values and Loss of Precision. Can you force the new server to run the process 32bit, does it change anything?

## awk. Rounding the result of division

By : Vasily Vasilevich
Date : March 29 2020, 07:55 AM
this one helps. In the first script you are printing the value n and awk knows to treat it as a number however in the second script you are printing n" "el which is treated as a string because you are using string concatenation. What you want to do instead is print n,el.
I would write the script like:
code :
``````\$ awk '{u[\$1]+=\$2;c[\$1]+=1}END{for(i in u)print i,u[i]/c[i]}' OFMT="%.2f" file
user1 230230
user2 273727.50
user3 187122.33
user4 212345
user5 141963
``````

## Linq to SQL rounding of decimal after division

Date : March 29 2020, 07:55 AM
I wish this help you This is definitely due to how SQL Server handles precision & scale in calculations.
If you change @mikeymouses example to use a scale of 6 for @p1 you get consistent results:
code :
``````DECLARE @p2 Decimal(28,6) = 1000000
DECLARE @p3 Decimal(28,18) = 453.59237

select @p3 / @p2

DECLARE @p1 Decimal(19,18) = 1  -- This is how Linq sends the * 1m

select @p3 / (@p2 *@p1)
select (@p3 *@p1) / @p2
``````

## Rounding the result of division in Javascript

By : user3799384
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Modern browsers should support a method called toFixed(). Here's an example taken from the web: 