rounding

Java - rounding by quarter intervals

喜夏-厌秋 提交于 2019-12-24 17:43:06
问题 I'm running into following issue... Does an already 'built-in' function exists in java to round given random numbers to the closest lower quarter value. These are the given random numbers: 2.00 -> 2.00 2.24 -> 2.00 2.25 -> 2.25 2.49 -> 2.25 2.50 -> 2.50 2.74 -> 2.50 2.75 -> 2.75 2.99 -> 2.75 3.00 -> 3.00 回答1: You can multiply the value by 4 then floor it then divide by 4. public static double quarterRound(double v){ return Math.floor(v*4)/4; } 回答2: You need to round to quarters so: Multiply

css browser pixel rounding / overflow hidden with percentages

笑着哭i 提交于 2019-12-24 17:23:30
问题 I am trying to make a scalable grid layout with CSS and I ve came across 2 problems that drive me nuts, so any help is greatly appreciated 1) I have a div with width set to 100% (with overflow hidden) so it covers the full browser window and inside the div I am trying to place ,say 5, divs one next to the other with width 20% but the last one that i want it to be slightly wider (21%). Although i have overflow hidden on the parent container the last div is wrapped below the other four instead

Round values in java

最后都变了- 提交于 2019-12-24 14:08:19
问题 How will I round 1 < value < 1.5 to 1.5 1.5 < value < 2 to 2 回答1: How about double rounded = Math.ceil(number * 2) / 2; Since Math.ceil() already returns a double, no need to divide by 2.0d here. This will work fine as long as you're in the range of integers that can be expressed as doubles without losing precision, but beware if you fall out of that range. 回答2: public double foo(double x){ int res = Math.round(x); if(res>x) // x > .5 return res -0.5; else return res + 0.5; } I havent

Taylor Series Difference between exp(-x) and exp(+x)

微笑、不失礼 提交于 2019-12-24 13:40:15
问题 I'm trying to write a program which calculates the Taylor series of exp(-x) and exp(x) up to 200 iterations, for large x. (exp(x)=1+x+x^2/2+...). My program is really simple, and it seems like it should work perfectly. However it diverges for exp(-x), but converges just fine for exp(+x). Here is my code so far: long double x = 100.0, sum = 1.0, last = 1.0; for(int i = 1; i < 200; i++) { last *= x / i; //multiply the last term in the series from the previous term by x/n sum += last; //add this

Testing for rounding errors due to Floating Point limitations

早过忘川 提交于 2019-12-24 12:27:37
问题 I have recently learned about one of the main limitations of floating points: The fact that some numbers can not be represented properly in binary and might therefore give answers which are not accurate enough for your purpose. Knowing that round(2.675, 2) and round(2.665, 2) both equal 2.67 I tried to write some code that would give a list of numbers that have this property (being rounded improperly). See my code below or in this replit: https://repl.it/@FTBlover123/Float-Rounding-Test Test

BigDecimal Rounding modes

此生再无相见时 提交于 2019-12-24 10:51:02
问题 We are replacing some sybase code to Java and having issue with Rounding BigDecimal to match what sybase returns 11.4443999999999999062083588796667754650115966796875 - Should return 11.44 and 35.9549999999999982946974341757595539093017578125 - should return 35.96 I have tried all different rounding options with scale set to 2, but none works for both. What is the best option? 回答1: You'll have to take a two-step approach. First round to scale 3, then to scale 2, using RoundingMode.HALF_UP :

LINQ to Entities does not recognize the method Double Round(Double, Int32, System.MidpointRounding) method

大兔子大兔子 提交于 2019-12-24 10:44:34
问题 I've tried the below LINQ Query in Linqer it is working fine but it is giving the below error while i tried with C# from IHeal_Mnt_Tickets in iHealEntities.iHeal_Mnt_Tickets where Tickets.Active == 1 && Tickets.MntID == 1 && Tickets.InsertedOn >= fromdate && Mnt_Tickets.InsertedOn <= todate && (new string[] { "Resolved", "Assigned" }).Contains(Tickets.status) group Tickets by new { Tickets.Instance } into g select new { Instance = g.Key.Summus_Instance, Assigned = (Int64?)g.Count(p => p

How to round time to nearest 15 minute in java

跟風遠走 提交于 2019-12-24 09:29:00
问题 My program needs to calculate the overtime periods of workers for salary calculation purposes. To this end, what I am doing now is getting the worker's clock-in time and out time, then I calculate with the company's time scales and get how many hours overtime each worker has done. I need to round these times to the nearest 15 minutes, so I need a class to pass in the hours and return the rounded hours. For example: if the overtime hours is 2.17 hrs it must be rounded to 2.15. if the overtime

Function round php not work correctly

喜你入骨 提交于 2019-12-24 08:56:48
问题 php function round not working correctly. I have number 0.9950 . I put code: $num = round("0.9950", 2); And I get 1.0? Why?? Why I can't get 0.99 ? 回答1: You can add a third parameter to the function to make it do what you need. You have to choose from one of the following : PHP_ROUND_HALF_UP PHP_ROUND_HALF_DOWN PHP_ROUND_HALF_EVEN PHP_ROUND_HALF_ODD This constants are easy enough to understand, so just use the adapted one :) In your example, to get 0.99, you'll need to use : <?php echo round(

How to round a double value to a selected number of decimals in .NET?

自闭症网瘾萝莉.ら 提交于 2019-12-24 07:35:24
问题 I use an acceleration sensor to calculate the current accelerations and it returns the double value. However I would like to compare the current acceleration with value 9.8. Before doing that i have to round the value received from the sensor so the question is: How to round a double value to a selected number of decimals in .NET? 回答1: Math.Round(number, precision) http://msdn.microsoft.com/en-us/library/zy06z30k.aspx 回答2: Math.Round - i.e. double val = Math.Round(current, 1); // 1dp 来源: