rounding

fstcw assembly operand type mismatch

浪子不回头ぞ 提交于 2019-12-11 20:07:29
问题 I'm trying to round an input double using a specified rounding mode in in-line assembly in C. To do so, I need to grab the FPU control word using "fstcw" and then change the bits in the word. Unfortunately I'm encountering an error on the very first line: double roundD(double n, RoundingMode roundingMode) { asm("fstcw %%ax \n" ::: "ax"); //clobbers return n; } The assembler error I receive is: "Error: operand type mismatch for 'fstcw'." I'm under the impression this code snippet should store

How to round a Python Decimal to 2 decimal places?

断了今生、忘了曾经 提交于 2019-12-11 19:27:23
问题 I've got a python Decimal (a currency amount) which I want to round to two decimal places. I tried doing this using the regular round() function. Unfortunately, this returns a float, which makes it unreliable to continue with: >>> from decimal import Decimal >>> a = Decimal('1.23456789') >>> type(round(a, 2)) <type 'float'> in the decimal module, I see a couple things in relation to rounding: ROUND_05UP ROUND_CEILING ROUND_DOWN ROUND_FLOOR ROUND_HALF_DOWN ROUND_HALF_EVEN ROUND_HALF_UP ROUND

Rounding in Java? [duplicate]

我是研究僧i 提交于 2019-12-11 19:06:52
问题 This question already has answers here : Floating point arithmetic not producing exact results [duplicate] (7 answers) Closed 4 years ago . My assignment is as follows: Read 20 pairs of numbers (ID number and score respectively) into two separate arrays. Find the average score. Print a table as shown below of the ID, score and difference (score - average) for each student, one student per line. Print the sum, average, and count of score at the head of the table as shown. Round the average and

Drop trailing digits of a floating point number

限于喜欢 提交于 2019-12-11 18:15:33
问题 I have some float variables in my java program: float var1=1.23456f; float var2=2.34567f; In my calculations, the number of digits after decimal point in my float variable increases and decreases to maintain precision. for e.g. after some calculations System.out.println(var1); may print: 6.35 or 9.4500082E or 88.25214 I want to round off these values to 3 decimal places and drop the subsequent decimal digits so that float gets rounded off like: 6.350 9.450 88.252 As far as i know, The

PHP Scientific Notation Shortening

谁都会走 提交于 2019-12-11 17:57:19
问题 I'm looking for an elegant solution here (if one exists). I've got a bunch of numbers, with an arbitrary amount of decimal places. I want to force the number to use 8 decimal places if it's got more than 8 trailing zeroes i.e. 0.000000004321 That would be converted to: 0.00000001 But I don't want to use number format because if I force it to 8 decimals with number format my numbers without 8 decimal places will look like: 1.00000000 I'd rather these just look like (for amounts >= 1): 1

Increasing Decimal Positions - Swirl - r Programming Environment 12 - Data Manipulation

蹲街弑〆低调 提交于 2019-12-11 17:31:49
问题 I am working on a question from swirl, r Programming Environment 12 Data Manipulation. I cannot figure out how to get r to give me the right number of digits after the decimal place. My code: titanic_4 <- titanic %>% select(Survived, Pclass, Age, Sex) %>% filter(!is.na(Age)) %>% mutate(agecat = cut(Age, breaks = c(0, 14.99, 50, 150), include.lowest = TRUE, labels = c("Under 15", "15 to 50", "Over 50"))) %>% group_by(Pclass,agecat,Sex) %>% summarize(N=n(), survivors = sum(Survived))%>% mutate

How to round up integer in PHP?

柔情痞子 提交于 2019-12-11 17:16:38
问题 I want to round up any an integer to the next tens place number. Some examples to illustrate my point: -- I have the number 1, I would like this rounded up to 10 -- I have the number 35, I would like this rounded up to 40 -- I have the number 72, I would like this rounded up to 80 -- etc etc // $category_count's value is 38 for($i = 1; $i <= $category_count; $i++) { if($i % 10 == 0) { echo "<a href=\"?page=$i\">$i;</a>"; } } The above code outputs 3 links, I need the fourth too. 回答1: Your for

Force Rounding to Equal the Sum

半腔热情 提交于 2019-12-11 16:57:14
问题 I work for a large company that presents rounded numbers in its financial statements. Of course, the rounded numbers do not always equal the total. I want the component number(s) that are closest to $0.50 to be rounded up or down so that the column equals the total. As an example, if I have the numbers 5.43, 4.26, and 6.32, they total 16.01. Rounded, they would be 5, 4, and 6 and the total would be 15. I want the total to be rounded to 16 and the closest amount to $X.50 to round the necessary

How can i round off data to mark it as interpolated or stale by suffixing in 0.0000001 or 0.0000002?

久未见 提交于 2019-12-11 15:55:18
问题 I have some missing data like :-- 1995 1996 1997 1998 1999 4 NA NA 5 NA what i want to do here is this :- 1995 1996 1997 1998 1999 4 4.3300001 4.6700001 5 5.0000002 Iam able to write code for the above interpolation (missing and stale data) but........ The data i input is not always clean. It might come as 1995 1996 1997 1998 1999 4.032 NA NA 5.134 5.0000002 This might interrupt with the precision of the interpolated numbers (who go to 7 decimal places) So i wanted to round off the data

Super odd C++ black hole in int and float

笑着哭i 提交于 2019-12-11 15:18:00
问题 Basically im trying to enter a value into the console, and output the decimal point as a whole number, and thats what needs to essentially occur. I've developed a way to do this, using float, int and simple maths. I'm still new to C++ but this error is not making sense. If you enter 0.01, 0.02, 0.03, 0.04, 0.06 or 0.08 you get the wrong output. I basically want to make it as simple as 0.06 * 100 = 6. I'm pretty sure its a simple mistake, but why is this so, when clearly I'm entering a whole