rounding

css calc function bug in IE

余生长醉 提交于 2019-12-17 16:50:28
问题 EDIT As @Joe pointed out in his answer, the problem here with IE has nothing to do with media queries. I have therefore updated the old title: ("media queries GLITCH in IE") with the current one. (thanks also to some meta advice) Just to be sure, I created a new FIDDLE containing just the calc function, and low and behold - I see the same (bad) behavior in IE as I did in my original fiddle with the media queries. Also, one interesting observation which I noticed was that this only happens

Best method to round up to the nearest 0.05 in java

浪尽此生 提交于 2019-12-17 16:49:37
问题 Consider that a tax of 10% is applicable on all items except food. Also, an additional tax of of 5 % is applicable on imported items. If the cost of a music CD is 12.49. The tax for the item will be 1.499. If the cost of an imported bottle of perfume is 47.50, The tax on the item will be 7.125 There is a policy in place which says that taxes on an item should be rounded off to the nearest 0.05. Therefore, 1.499 should be rounded off to 1.5 and 7.125 should be rounded of to 7.25. The above

Convert double to Int, rounded down

别等时光非礼了梦想. 提交于 2019-12-17 16:24:11
问题 How to convert a double value to int doing the following: Double If x = 4.97542. Convert to int x = 4. Double If x = 4.23544. Convert to int x = 4. That is, the answer is always rounding down. 回答1: If you explicitly cast double to int , the decimal part will be truncated. For example: int x = (int) 4.97542; //gives 4 only int x = (int) 4.23544; //gives 4 only Moreover, you may also use Math.floor() method to round values in case you want double value in return. 回答2: If the double is a Double

Double vs Decimal Rounding in C#

柔情痞子 提交于 2019-12-17 14:47:10
问题 Why does: double dividend = 1.0; double divisor = 3.0; Console.WriteLine(dividend / divisor * divisor); output 1.0, but: decimal dividend = 1; decimal divisor = 3; Console.WriteLine(dividend / divisor * divisor); outputs 0.9999999999999999999999999999 ? I understand that 1/3 can't be computed exactly, so there must be some rounding. But why does Double round the answer to 1.0, but Decimal does not? Also, why does double compute 1.0/3.0 to be 0.33333333333333331? If rounding is used, then

Why does PHP's sprintf not round 5s reliably?

南笙酒味 提交于 2019-12-17 14:31:09
问题 I was relying on sprintf('%0.1f', 2.25) === '2.3' but it turns out it comes in at 2.2 ! In fact it seems random: php > for ($j=0;$j<=10;$j++) { printf( "%s -> %0.1f\n",$j+ 0.05, $j+0.05); } 0.05 -> 0.1 // Up, as expected 1.05 -> 1.1 // Up, as expected 2.05 -> 2.0 // Down! 3.05 -> 3.0 // Down! 4.05 -> 4.0 // Down! 5.05 -> 5.0 // Down! 6.05 -> 6.0 // Down! 7.05 -> 7.0 // Down! 8.05 -> 8.1 // Up, as expected 9.05 -> 9.1 // Up, as expected Have I completely missed the point? I feel like a rug is

Round a POSIX date (POSIXct) with base R functionality

心已入冬 提交于 2019-12-17 10:52:56
问题 I'm currently playing around a lot with dates and times for a package I'm building. Stumbling across this post reminded me again that it's generally not a bad idea to check out if something can be done with basic R features before turning to contrib packages. Thus, is it possible to round a date of class POSIXct with base R functionality? I checked methods(round) which "only" gave me [1] round.Date round.timeDate* Non-visible functions are asterisked This is what I'd like to do (Pseudo Code)

JavaScript: Round to a number of decimal places, but strip extra zeros

社会主义新天地 提交于 2019-12-17 10:23:47
问题 Here's the scenario: I'm getting .9999999999999999 when I should be getting 1.0 . I can afford to lose a decimal place of precision, so I'm using .toFixed(15) , which kind of works. The rounding works, but the problem is that I'm given 1.000000000000000 . Is there a way to round to a number of decimal places, but strip extra whitespace? Note: .toPrecision isn't what I want; I only want to specify how many numbers after the decimal point. Note 2: I can't just use .toPrecision(1) because I need

round down to 2 decimal in python

早过忘川 提交于 2019-12-17 09:55:46
问题 I need to round down and it should be two decimal places. Tried the following, a = 28.266 print round(a, 2) 28.27 But the expected value is 28.26 only. 回答1: Seems like you need the floor : import math math.floor(a * 100)/100.0 # 28.26 回答2: It seems you want truncation, not rounding. A simple way would be to combine floor division // and regular division / : >>> a = 28.266 >>> a // 0.01 / 100 28.26 Instead of the regular division you could also multiply (as noted in the comments by cmc): >>> a

round BigDecimal to nearest 5 cents

送分小仙女□ 提交于 2019-12-17 09:47:38
问题 I'm trying to figure out how to round a monetary amount upwards to the nearest 5 cents. The following shows my expected results 1.03 => 1.05 1.051 => 1.10 1.05 => 1.05 1.900001 => 1.10 I need the result to be have a precision of 2 (as shown above). Update Following the advice below, the best I could do is this BigDecimal amount = new BigDecimal(990.49) // To round to the nearest .05, multiply by 20, round to the nearest integer, then divide by 20 def result = new BigDecimal(Math.ceil(amount

printf rounding behavior for doubles

与世无争的帅哥 提交于 2019-12-17 09:40:15
问题 Can someone explain this behavior? I am well aware of machine-level representation of floating point numbers. This seems to be related to printf and its formats. Both numbers are represented exactly by floating-point notation (check: multiplying by 64 gives an integer). #include <stdio.h> #include <iostream> using namespace std; int main() { double x1=108.765625; printf("%34.30f\n", x1); printf("%9.5f\n", x1); printf("%34.30f\n", x1*64); double x2=108.046875; printf("%34.30lf\n", x2); printf(