rounding

Round date to 10 minutes interval

被刻印的时光 ゝ 提交于 2019-12-12 08:21:32
问题 I have a DATE column that I want to round to the next-lower 10 minute interval in a query (see example below). I managed to do it by truncating the seconds and then subtracting the last digit of minutes. WITH test_data AS ( SELECT TO_DATE('2010-01-01 10:00:00', 'YYYY-MM-DD HH24:MI:SS') d FROM dual UNION SELECT TO_DATE('2010-01-01 10:05:00', 'YYYY-MM-DD HH24:MI:SS') d FROM dual UNION SELECT TO_DATE('2010-01-01 10:09:59', 'YYYY-MM-DD HH24:MI:SS') d FROM dual UNION SELECT TO_DATE('2010-01-01 10

Rounding of negative numbers in Javascript

大兔子大兔子 提交于 2019-12-12 07:57:34
问题 We have come across a problem with Math.round() in JavaScript. The problem is that this function doesn't round correctly for negative numbers. For example : 1.5 ~= 2 0.5 ~= 1 -0.5 ~= 0 // Wrong -1.5 ~= -1 // Wrong And this is not correct according to arithmetic rounding. The correct numbers for -0.5 should be -1 and -1.5 should be -2. Is there any standard way, to correctly round negative numbers in Javascript ? 回答1: You could save the sign and apply later, in ES5; function round(v) { return

Is there a more readable or Pythonic way to format a Decimal to 2 places?

情到浓时终转凉″ 提交于 2019-12-12 06:45:16
问题 What the heck is going on with the syntax to fix a Decimal to two places? >>> from decimal import Decimal >>> num = Decimal('1.0') >>> num.quantize(Decimal(10) ** -2) # seriously?! Decimal('1.00') Is there a better way that doesn't look so esoteric at a glance? 'Quantizing a decimal' sounds like technobabble from an episode of Star Trek! 回答1: Use string formatting: >>> from decimal import Decimal >>> num = Decimal('1.0') >>> format(num, '.2f') '1.00' The format() function applies string

Rounding the SIGNIFICANT digits in a double, not to decimal places [duplicate]

无人久伴 提交于 2019-12-12 06:20:13
问题 This question already has answers here : Round a double to x significant figures (13 answers) Closed 4 years ago . I need to round significant digits of doubles. Example Round(1.2E-20, 0) should become 1.0E-20 I cannot use Math.Round(1.2E-20, 0), which returns 0, because Math.Round() doesn't round significant digits in a float, but to decimal digits, i.e. doubles where E is 0. Of course, I could do something like this: double d = 1.29E-20; d *= 1E+20; d = Math.Round(d, 1); d /= 1E+20; Which

Two questions for formatting timestamp and number using postgresql

六月ゝ 毕业季﹏ 提交于 2019-12-12 04:16:05
问题 I am selecting a date column which is in the format "YYYY-MM-DD". I want to cast it to a timestamp such that it will be "YYYY-MM-DD HH:MM:SS:MS" I attempted: select CAST(mycolumn as timestamp) from mytable; but this resulted in the format YYYY-MM-DD HH:MM:SS I also tried select TO_TIMESTAMP(mycolumn,YYYY-MM-DD HH:MM:SS:MS) from mytable; but this did not work either. I cannot seem to figure out the correct way to format this. Note that I only want the first digit of the milliseconds. /////////

Why is my webgl shader not changing pixel fragments correctly?

拜拜、爱过 提交于 2019-12-12 02:57:47
问题 I'm trying to get position of a fragment and change the color at positions, but when I try to do it, I get a weird effect where they don't want to be changed completely. Notice how there is a cyan color, but that part should be transparent. It seems like there's some weird rounding happening, and I'm not sure how to fix it. What is happening here? void main() { vec4 c0 = vec4(0,1,0,1); c0.a *= step(132.0,gl_FragCoord.x); gl_FragColor = c0; } 回答1: You need to show more code. Did you enable

float deviation in python list [duplicate]

眉间皱痕 提交于 2019-12-12 02:08:37
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Python float - str - float weirdness I run the following code in python on codepad.org: num = 1.6 print num list = [num] print list num2 = list[0] print num2 And I get the following output: 1.6 [1.6000000000000001] 1.6 Why the tiny deviation in the list? 回答1: list.__str__ calls repr on its elements, where as print calls str : >>> str(1.6) '1.6' >>> repr(1.6) '1.6000000000000001' Since floating point numbers are

Rounding of variables

最后都变了- 提交于 2019-12-12 00:26:35
问题 I have the following code: x=4200/820 It should return x=5.12 but it gives x=5 . How can I change this. Thanks EDIT: If instead I had this code: x=(z-min(z_levels))/(max(z_levels)-min(z_levels)) Where z, min(z_levels) and max(z_levels) are values that change in a for loop taken from a list. How can I make x a float? Do I need to change the code like this:? x=float(z-min(z_levels))/float(max(z_levels)-min(z_levels)) 回答1: In python2.x integer division always results in truncated output, but if

Draw image in canvas with decimal values

狂风中的少年 提交于 2019-12-11 23:52:20
问题 I am trying to draw an image originating from a list of X,Y values that represent the start and stop points of a line. They are in inches, so they are currently formatted in to decimals. The problem I am having is with the drawing. The MoveTo and LineTo commands require an integer not a double. If I use the Round(float) math operation, you see the output below. The rounding results in the same start and stop point, so nothing is drawn. How can I draw my shape from a list of decimal X,Y points

Add a rounding method to Number.prototype in JavaScript

夙愿已清 提交于 2019-12-11 20:24:30
问题 How can I simplify rounding in JavaScript? I wish that I could do it in a more elegantly in an object-oriented manner. The method toFixed works well, but does not have backward rounding and it also returns a string and not a number. pi.toFixed(2).valueOf(); // 3.14 As it is, rounding is a bit of a tangle because I have to use: pi = Math.round(pi * 100) / 100; // 3.14 It would be much nicer instead just to stick a method to the end of a variable, such as: pi.round(2); // 3.1r 回答1: Extend