rounding

Rounding % Labels on bar chart in ggplot2

孤者浪人 提交于 2019-12-30 07:59:23
问题 q1 <- qplot(factor(Q1), data=survey, geom="histogram", fill=factor(Q1), ylim=c(0,300)) options(digits=2) q1 + geom_bar(colour="black") + stat_bin(aes(label=..count..), vjust=-2, geom="text", position="identity") + stat_bin(geom="text", aes(label=paste(..count../sum(..count..)*100,"%"), vjust=-0.75)) + labs(x="Question # 1:\n 0 = Didn't respond, 1 = Not at all familiar, 5 = Very familiar") + opts(title="Histogram of Question # 1:\nHow familiar are you with the term 'Biobased Products'?",

Rounding up to the nearest 0.05 in JavaScript

我的未来我决定 提交于 2019-12-30 05:58:06
问题 Question Does anyone know of a way to round a float to the nearest 0.05 in JavaScript? Example BEFORE | AFTER 2.51 | 2.55 2.50 | 2.50 2.56 | 2.60 Current Code var _ceil = Math.ceil; Math.ceil = function(number, decimals){ if (arguments.length == 1) return _ceil(number); multiplier = Math.pow(10, decimals); return _ceil(number * multiplier) / multiplier; } Then elsewhere... return (Math.ceil((amount - 0.05), 1) + 0.05).toFixed(2); Which is resulting in... BEFORE | AFTER 2.51 | 2.55 2.50 | 2.55

round value to 2 decimals javascript

核能气质少年 提交于 2019-12-30 01:47:29
问题 I have a small issue with the final value, i need to round to 2 decimals. var pri='#price'+$(this).attr('id').substr(len-2); $.get("sale/price?output=json", { code: v }, function(data){ $(pri).val(Math.round((data / 1.19),2)); }); }); Any help is appreciated. Solution: $(pri).val(Math.round((data / 1.19 * 100 )) / 100); 回答1: Just multiply the number by 100, round, and divide the resulting number by 100. 回答2: If you want it visually formatted to two decimals as a string (for output) use

Where is Round() in C++? [duplicate]

微笑、不失礼 提交于 2019-12-29 04:28:07
问题 This question already has answers here : Closed 10 years ago . Duplicate of: round() for float in C++ I'm using VS2008 and I've included math.h but I still can't find a round function. Does it exist? I'm seeing a bunch of "add 0.5 and cast to int" solutions on google. Is that the best practice? 回答1: You may use C++11's std::round(). If you are still stuck with older standards, you may use std::floor(), which always rounds to the lower number, and std::ceil(), which always rounds to the higher

javascript number precision without converting to String

折月煮酒 提交于 2019-12-29 02:11:10
问题 I am developing a REST API and returning JSON. One of the fields is called submissionPercent and I need it to be a number but with exactly 2 decimal places If the submissionPercent is 20, I need to return 20.00. If the submissionPercent is 20.238, I need to return 20.24. But submissionPercent should be a number not a String. If I use toFixed or toPrecision , then what I get is a String. If possible, how do I achieve this? 回答1: var n = 20.238; Math.round(n * 100) / 100 // => 20.24 Or more

how to always round up to the next integer [duplicate]

好久不见. 提交于 2019-12-28 09:32:10
问题 This question already has answers here : How can I ensure that a division of integers is always rounded up? (8 answers) Closed 2 years ago . i am trying to find total pages in building a pager on a website (so i want the result to be an integer. i get a list of records and i want to split into 10 per page (the page count) when i do this: list.Count() / 10 or list.Count() / (decimal)10 and the list.Count() =12 , i get a result of 1 . How would I code it so i get 2 in this case (the remainder

How to perform round to even with floating point numbers

自作多情 提交于 2019-12-28 08:09:10
问题 In regards to IEEE-754 single precision floating point, how do you perform round to nearest, where ties round to the nearest even digit in the required position (the default and by far the most common mode)? Basically I have the guard bit, round bit, and sticky bit. So if we form those into a vector and call it GRS, then the following rules apply: If G = 0 , round down (do nothing) If G = 1 , and RS == 10 or RS == 01 , round up (add one to mantissa) if GSR = 111 , round to even So I am not

How to perform round to even with floating point numbers

笑着哭i 提交于 2019-12-28 08:09:05
问题 In regards to IEEE-754 single precision floating point, how do you perform round to nearest, where ties round to the nearest even digit in the required position (the default and by far the most common mode)? Basically I have the guard bit, round bit, and sticky bit. So if we form those into a vector and call it GRS, then the following rules apply: If G = 0 , round down (do nothing) If G = 1 , and RS == 10 or RS == 01 , round up (add one to mantissa) if GSR = 111 , round to even So I am not

Always Round UP a Double

让人想犯罪 __ 提交于 2019-12-28 06:28:05
问题 How could I always round up a double to an int , and never round it down. I know of Math.round(double) , but I want it to always round up. So if it was 3.2 , it gets rounded to 4. 回答1: You can use Math.ceil() method. See JavaDoc link: https://docs.oracle.com/javase/10/docs/api/java/lang/Math.html#ceil(double) From the docs: ceil public static double ceil(double a) Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a

Java: round to nearest multiple of 5 (either up or down)

北慕城南 提交于 2019-12-28 05:35:07
问题 I need to round a number to nearest multiple of 5 (either up or down). For example, here are the list of numbers and the number next to it that it needs to round up/down to. 12.5 10 62.1 60 68.3 70 74.5 75 80.7 80 Numbers will only be positive. 回答1: haven't tested it, but 5*(Math.round(f/5)); should work 回答2: Nearest Multiple of 5 for Upper value 5*(Math.ceil(Math.abs(number/5))); for Lower Value 5*(Math.floor(Math.abs(number/5))); it gives Positive value only. 回答3: public static void main