rounding

Undesired rounding of DateTime in SQL Server

只愿长相守 提交于 2019-12-18 07:36:52
问题 I ran into something that seems odd. SQL Server appears to be rounding some DateTime values inappropriately when I save them to datetime columns. I suspect I'm missing something, but I can't spot it. I'm running this test against SQL Server 2008 using .NET 4.0. The following should illustrate the issue: I have created a table in in SQL Server called Timestamps. It has two columns: id - bigint, Identity, PK timestamp - datetime I also created a simple test that does the following: Gets the

How to limit a decimal number? [duplicate]

孤街醉人 提交于 2019-12-18 07:31:16
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: How to format a decimal How can I limit my decimal number so I'll get only 3 digits after the point? e.g 2.774 回答1: Math.Round Method (Decimal, Int32) Example: Math.Round(3.44, 1); //Returns 3.4. 回答2: I'm assuming you really mean formatting it for output: Console.WriteLine("{0:0.###}", value); 回答3: To get Decimal back use Math.Round with Second parameter specifying number of decimal points. decimal d = 54.9700M;

How to limit a decimal number? [duplicate]

♀尐吖头ヾ 提交于 2019-12-18 07:30:38
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: How to format a decimal How can I limit my decimal number so I'll get only 3 digits after the point? e.g 2.774 回答1: Math.Round Method (Decimal, Int32) Example: Math.Round(3.44, 1); //Returns 3.4. 回答2: I'm assuming you really mean formatting it for output: Console.WriteLine("{0:0.###}", value); 回答3: To get Decimal back use Math.Round with Second parameter specifying number of decimal points. decimal d = 54.9700M;

JavaScript: Rounding Down in .5 Cases

让人想犯罪 __ 提交于 2019-12-18 06:13:20
问题 I am in a situation where a JavaScript function produces numbers, such as 2.5 . I want to have these point five numbers rounded down to 2 , rather than the result of Math.round , which will always round up in such cases (ignoring the even odd rule), producing 2. Is there any more elegant way of doing this than subtracting 0.01 from the number before rounding? Thanks. 回答1: Just negate the input and the output to Math.round : var result = -Math.round(-num); In more detail: JavaScript's Math

“width: calc(100% / 3);” not working properly in any IE

送分小仙女□ 提交于 2019-12-18 05:43:31
问题 I have a 3 column layout that should fill the whole screen so on my columns I am using: width: calc(100% / 3); So lets say for example my screen is 782px wide: 782 / 3 = 260.66̅ However the problem I have is in Internet Explorer, where it rounds the pixels to two decimal places (260.67) 260.67 * 3 = 782.01 So at certain widths, I lose a 1/3 of my page as it wraps underneath. Here's an example: function onResize() { $('ul').each(function() { var H = eval($(this).height() / $(this).children('li

toFixed(2) rounds “x.525” inconsistently?

江枫思渺然 提交于 2019-12-18 04:54:38
问题 I'm experiencing rounding errors when using toFixed: I used toFixed(2) on my numeric value calculations, but the rounding results are not as expected for few cases. Suppose that toFixed(2) is applied for value 17.525 then it gives the result 17.52 , And if it is applied for 5.525 then it gives the result 5.53 . In the later case the rounding result is accurate, so can you please suggest what needs to be done to get the accurate rounding result as in the later case. Or can you please suggest

C# how to always round down to nearest 50

大城市里の小女人 提交于 2019-12-18 04:34:23
问题 I've done a search on C# rounding, but haven't been able to find the answer to my current problem. What I want to do is always round down to the nearest 50. All the values I want to round down will be in decimal. So 635.25 would be 600. 298.42 would be 250. 149.56 would be 100. I've looked at math.round but how would I use that so it always rounds down to the nearest 50 and never up? 回答1: Divide the value by 50, round down to the closest whole number, and multiply by 50 again: double n = Math

Python - round up to the nearest ten [duplicate]

℡╲_俬逩灬. 提交于 2019-12-18 04:28:13
问题 This question already has answers here : Python round up integer to next hundred (8 answers) How to round integers in python (7 answers) Closed 5 years ago . If I get the number 46 and I want to round up to the nearest ten. How do can I do this in python? 46 goes to 50. 回答1: You can use math.ceil() to round up, and then multiply by 10 import math def roundup(x): return int(math.ceil(x / 10.0)) * 10 To use just do >>roundup(45) 50 回答2: round does take negative ndigits parameter! >>> round(46,

Why does Convert.ToInt32() round to the nearest even number, instead of nearest whole number? [closed]

我的未来我决定 提交于 2019-12-18 03:51:25
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Looking at the msdn documentation for Convert.ToInt32() it states: If value is halfway between two whole numbers, the even number is

cast variable to int vs round() function

久未见 提交于 2019-12-18 03:49:34
问题 I have seen it in several places where (int)someValue has been inaccurate and instead the problem called for the round() function. What is the difference between the two? Specifically, if need be, for C99 C. I have also seen the same issue in my programs when writing them in java. 回答1: In case of casting a float / double value to int , you generally loose the fractional part due to integer truncation . This is quite different from rounding as we would usually expect, so for instance 2.8 ends