rounding

round a date in R to an arbitrary minute/hour level of precision

て烟熏妆下的殇ゞ 提交于 2021-02-04 17:07:33
问题 I'm looking to group dates in R by an arbitrary level of precision. It's pretty straightforward to do this to the nearest hour or minute, using e.g. lubridate : library(lubridate) nearest_hour = floor_date(now(), 'hour') You can then group a list of such dates with e.g. a simple summarise ddply from plyr . What I'd like to do is round dates with arbitrary precision, e.g. to the nearest 15 minutes or every 3 hours: nearest_three_hours = floor_date(now(), '3 hours') There's a discussion of such

round a date in R to an arbitrary minute/hour level of precision

北慕城南 提交于 2021-02-04 17:07:28
问题 I'm looking to group dates in R by an arbitrary level of precision. It's pretty straightforward to do this to the nearest hour or minute, using e.g. lubridate : library(lubridate) nearest_hour = floor_date(now(), 'hour') You can then group a list of such dates with e.g. a simple summarise ddply from plyr . What I'd like to do is round dates with arbitrary precision, e.g. to the nearest 15 minutes or every 3 hours: nearest_three_hours = floor_date(now(), '3 hours') There's a discussion of such

round up/down float to 2 decimals

一世执手 提交于 2021-02-04 06:28:46
问题 I would like to design a function f(x : float, up : bool) with these input/output: # 2 decimals part rounded up (up = True) f(142.452, True) = 142.46 f(142.449, True) = 142.45 # 2 decimals part rounded down (up = False) f(142.452, False) = 142.45 f(142.449, False) = 142.44 Now, I know about Python's round built-in function but it will always round 142.449 up, which is not what I want. Is there a way to do this in a nicer pythonic way than to do a bunch of float comparisons with epsilons

PHP Division results in automatically rounded up number

限于喜欢 提交于 2021-01-29 16:17:48
问题 I have a simple division: 72 / 193 Excel is giving me result of 0.373056994818653 While PHP round it up to 0.373056994819 My question is - how can I make PHP to give me the exact number instead of a rounded up one? 回答1: It isn't a question of being 'exact' or not, it is about precision. Wolfram Alpha has a much larger precision for your answer. You need to change the precision of your php configuration to suit how many units you need after the decimal. I cannot find the largest precision PHP

Given a constant frame rate H.264 MP4, how to get PTS rounding method used during encoding using ffmpeg?

ぃ、小莉子 提交于 2021-01-29 07:39:13
问题 ffmpeg can convert the video to specified constant frame rate. It has round parameter to specify timestamp(PTS) rounding method. It could be zero , int , down , up and near . Given a constant frame rate H.264 mp4 video, how can we determine which PTS rounding method was used to encode this video? 来源: https://stackoverflow.com/questions/63956476/given-a-constant-frame-rate-h-264-mp4-how-to-get-pts-rounding-method-used-durin

Given a constant frame rate H.264 MP4, how to get PTS rounding method used during encoding using ffmpeg?

耗尽温柔 提交于 2021-01-29 07:35:37
问题 ffmpeg can convert the video to specified constant frame rate. It has round parameter to specify timestamp(PTS) rounding method. It could be zero , int , down , up and near . Given a constant frame rate H.264 mp4 video, how can we determine which PTS rounding method was used to encode this video? 来源: https://stackoverflow.com/questions/63956476/given-a-constant-frame-rate-h-264-mp4-how-to-get-pts-rounding-method-used-durin

Create a range of decimal number using numpy does not work

为君一笑 提交于 2021-01-29 05:01:48
问题 I want to create a range of values between 521 and 522 with step 0.1. This is my code: ICD9CD1 = np.arange(521, 522, 0.1) The result is: array([521. , 521.1, 521.2, 521.3, 521.4, 521.5, 521.6, 521.7, 521.8, 521.9]) but when I want to covert it to a list, this is the result: np.arange(521, 522, 0.1).tolist() [521.0, 521.1, 521.2, 521.3000000000001, 521.4000000000001, 521.5000000000001, 521.6000000000001, 521.7000000000002, 521.8000000000002, 521.9000000000002] What part of my code is wrong? I

Rounding up and rounding down bill amount

感情迁移 提交于 2021-01-28 04:48:35
问题 I'm facing a problem to get the digit of a number after decimal point. I need the digit to do if else statement. Here is an example: 31.30 = 31.30 31.31 = 31.30 31.32 = 31.30 31.33 = 31.35 31.34 = 31.35 31.35 = 31.35 31.36 = 31.35 31.37 = 31.35 31.38 = 31.40 31.39 = 31.30 So, I need to get the second digit after decimal point. Then, i can use the digit to do if else statement. This rounding issue is happening in Malaysia. 回答1: Something like this might work for doing the rounding to the

Numpy array being rounded? subtraction of small floats

夙愿已清 提交于 2021-01-27 16:05:04
问题 I am assigning the elements of a numpy array to be equal to the subtraction of "small" valued, python float-type numbers. When I do this, and try to verify the results by printing to the command line, the array is reported as all zeros. Here is my code: import numpy as np np.set_printoptions(precision=20) pc1x = float(-0.438765) pc2x = float(-0.394747) v1 = np.array([0,0,0]) v1[0] = pc1x-pc2x print pc1x print pc2x print v1 The output looks like this: -0.438765 -0.394747 [0 0 0] I expected

rounding .5 down in java

坚强是说给别人听的谎言 提交于 2021-01-27 13:01:29
问题 How can you implement a rounding function which will round all numbers as usual except 0.5 or any odd multiple of it down to the nearest integer? For example: 2.899 is to be rounded up to 3.0 2.332 is to be rounded down to 2.0 2.5 is also to be rounded down to 2.0 (and NOT 3.0 ) 回答1: You can use BigDecimal as follows: public static double roundHalfDown(double d) { return new BigDecimal(d).setScale(0, RoundingMode.HALF_DOWN) .doubleValue(); } Example: for (double d : new double[] { 2.889, 2