rounding

Pandas data frame. Change float format. Keep type “float”

我的未来我决定 提交于 2019-12-11 04:04:16
问题 I'm trying to change a format of pd data frame column without changing the type of data. Here is what I have: df = pd.DataFrame({'Age': [24.0, 32.0}]) I'd like to represent Age in 24 32 type or 24.00 32.00 and keep them as floats. Here is what I can do: df['Age'].map('{:,.2f}'.format) But this line changes the type of data to object. I was also trying to apply: ` df = df.style.format({'Age': '{:,.2f}'.format})` but there is something wrong in it. Please help to figure out the right way. 回答1:

AngularJS {{ val | number:1 }} not rounding to 1 decimal place

徘徊边缘 提交于 2019-12-11 03:54:58
问题 <p> <b>{{ x.title }} </b> Rating:{{ x.rating | number:1}}</p> The above code is what I'm using. It is getting the value correctly because it is showing an unrounded number (e.g. 3.333333333) so I know the value is passed correctly. Why won't the number:# filter work? 回答1: I'm an idiot. CLEAR YOUR CACHE KIDS - It was working but hadn't reloaded my index.html file. 来源: https://stackoverflow.com/questions/29421770/angularjs-val-number1-not-rounding-to-1-decimal-place

Python - round a float to 2 digits

谁说我不能喝 提交于 2019-12-11 03:49:40
问题 I would need to have a float variable rounded to 2 significant digits and store the result into a new variable (or the same of before, it doesn't matter) but this is what happens: >>> a 981.32000000000005 >>> b= round(a,2) >>> b 981.32000000000005 I would need this result, but into a variable that cannot be a string since I need to insert it as a float... >>> print b 981.32 Actually truncate would also work I don't need extreme precision in this case. 回答1: What you are trying to do is in fact

What rounding method should you use in Java for money?

▼魔方 西西 提交于 2019-12-11 03:16:21
问题 Suppose I have a decimal value in Java that represents money. What's the best way to round these values? For example, if I have a value that's calculated based on a tax rate and I end up with a result of, say, 5.3999999999999995 as the tax amount, should I round it to 2 decimal places simply by doing this: double d = 5.3999999999999995 BigDecimal bd = new BigDecimal(d).setScale(2, RoundingMode.HALF_EVEN); d = bd.doubleValue(); to produce the currency value: 5.40 回答1: Most applications that

VBA Range.Find function on rounded negative numbers

帅比萌擦擦* 提交于 2019-12-11 02:32:55
问题 I'm having an issue with a VBA macro I wrote, with the part that is intended to find a lowest value in range. The line looks like this: Min = Application.WorksheetFunction.Min(a0eqB) Set MinCell = a0eqB.Find(Min, LookIn:=xlValues) And it returns Object variable or With block variable not set error. Now, I know why this happens - sometimes Find finds Nothing , and I learned how to handle this type of situations. Although, it also finds Nothing when the value that is dispayed in a cell differs

Oracle Rounding down

时光怂恿深爱的人放手 提交于 2019-12-11 02:29:20
问题 Here my partial statement. The statement works and receive the value of 4 but instead I would prefer 3.9 in some cases the number may not be a whole number but .4,.2,.1 etc. Those numbers currently show up as "0" because Oracle rounds up. If I remove "round" I receive 3.9123458543845474586. Is there a way to display 3.9 only and .4,.2 etc. without the rounding? I know its got to be a syntax issue. When I remove round I receive an error. round((total_qty)*((avg_qty/(sum(avg_qty)over(partition

Rounding in Python

谁都会走 提交于 2019-12-11 02:24:12
问题 round(1.4 999 999 999 999 999) (without the spaces) gets rounded to 2 but round(1.4 99 999 999 999 999) (without the spaces) gets rounded to 1. I suppose this has to do with imprecise floating point representations, but fail to understand how does it come that the first representation is interpreted as closer to 2 than to 1. 回答1: Because 1.4 999 999 999 999 999 when parsed is exactly 1.5, the difference between them is too small to represent at that magnitude. But 1.4 99 999 999 999 999 is

R, rounding, ceiling and floors

痴心易碎 提交于 2019-12-11 02:22:54
问题 Suppose that one has a bunch of data returned from pnorm(), such that you've got numbers between .0003ish and .9999ish. numbers <- round(rnorm(n = 10000, mean = 100, sd = 15)) percentiles <- pnorm(numbers, mean = 100, sd = 15)*100 And then further suppose that one is interested in rounding the percentiles such that .0003 or whatevs will come out to 1 (so ceiling()), but 99.999 will come out to 99 (so floor()). I guess what I'm looking for is round() that somehow brilliantly knows to reverse

python float formatting weirdness?

痴心易碎 提交于 2019-12-11 01:45:21
问题 I'm trying to debug two different python scripts that execute very similar code. These scripts set a , which is a simple float. For script 1: ipdb> print sys.version 2.7 (r27:82500, Jul 15 2010, 13:04:38) [GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] ipdb> type(a) <type 'float'> ipdb> print a 17.23105 ipdb> print '{0:.4f}'.format(a) 17.2311 For script 2: ipdb> print sys.version 2.7 (r27:82500, Jul 15 2010, 13:04:38) ipdb> print type(a) <type 'float'> ipdb> print a 17.23105 ipdb> print '{0:.4f}'

re-programming a semi-advanced rounding program

假装没事ソ 提交于 2019-12-11 01:45:00
问题 Hi all: I have a question related to a previous post about a rounding program (available here: R: Round the contents within each row so that the row total is equal to a number I specify). The program is designed to round the contents within each row so that the row total is equal to a number I specify. Copied from the original post, here is a MWE that works: Round <- function(x, target) { r.x <- round(x) diff.x <- round(x) - x if ((s <- sum(r.x)) == target) { return(r.x) } else if (s > target