rounding

Rounding values up or down in C#

混江龙づ霸主 提交于 2019-12-23 06:44:06
问题 I've created a game which gives a score at the end of the game, but the problem is that this score is sometimes a number with a lot of digits after the decimal point (like 87.124563563566). How would I go about rounding up or down the value so that I could have something like 87.12? Thanks! 回答1: Try using Math.Round. Its various overloads allow you to specify how many digits you want and also which way you want it to round the number. 回答2: Use Math.Ceiling(87.124563563566) or Math.Floor(87

Rounding to 6 decimal places using Math.round method in Java android

◇◆丶佛笑我妖孽 提交于 2019-12-23 05:29:32
问题 I'm using double i2 = value * 2.23694; i2 = (double)(Math.round(i2 * 100)) / 100; for rounding doubles. But it rounds to only 2 decimal places. I want it to be 6 decimal places. Is there any way to use Math.round and have 6 decimal places? 回答1: You are casting things to Integer s which will ruin any rounding. To use double s, use a decimal point (i.e 100.0 instead of 100 ). And if you want it with 6 decimals, use 1000000.0 like this: double i2 = value * 2.23694; i2 = Math.round(i2*1000000.0)

Java Graphics2D is Drawing One Pixel Off (Rounding error?)

梦想与她 提交于 2019-12-23 02:29:09
问题 I have been trying to make a program in Java using Graphics2D and PaintComponent. However, Java is not rounding some values correctly resulting in a few points being rendered a pixel different from where it supposed to be which gives an unclean image. You can see what I mean in the picture below. Here is my code. What can I change to fix this? Thank you! public void paintComponent( Graphics g ) { super.paintComponent( g ); g.setColor(Color.red); int orginX = getWidth()/2; int orginY =

Round up decimal number according to fraction in PHP

你说的曾经没有我的故事 提交于 2019-12-23 01:51:17
问题 I am working to convert an excel formula to php function. Now I am facing a problem that is round up as the fraction. Please let me explain it: (2 * 18)/2.98 = 12.08 but according to my requirement it should be 12.25 (2 * 18.5)/2.98 = 12.416 but according to my requirement it should be 12.50 (2 * 18.8)/2.98 = 12.617 but according to my requirement it should be 12.75 In excel, it is done like : ceiling(( 2 * 18 )/2.98, 0.25) = 12.25 ceiling(( 2 * 18.5 )/2.98, 0.25) = 12.50 ceiling(( 2 * 18.8 )

Why does the NSString class round inconsistently when formatting numbers?

做~自己de王妃 提交于 2019-12-23 01:41:57
问题 The output of the following two lines seem to show that NSString's stringWithFormat statement does not round numbers consistently. It seems to round up correctly from 0.75 to 0.8. But it rounds 0.25 down to 0.2. Here is the code. NSString *sRoundedScore = [NSString stringWithFormat:@"%.1f", fScore]; NSLog(@"\r\n score before rounding: %f, rounded score: %@", fScore, sRoundedScore); When fScore is assigned to be 0.25, the output is: score before rounding: 0.250000, rounded score: 0.2 When

Using LIKE to match floats when Rounding is not wanted

ぃ、小莉子 提交于 2019-12-22 18:45:25
问题 So here is what I am trying to accomplish. I have coordinate data in two tables, which I am trying to link together with an Association table. It is a one to one association, so if I have 40 records in table A, 40 records in table B, then I should have 40 records in the association table. Now the data in these two tables is approximately the same, but never idential, in fact they rarely even have the same precision. One table(we'll say A) always has 6 decimal places, whereas table B may have

Rounding a double number up to the tenths place [duplicate]

眉间皱痕 提交于 2019-12-22 17:53:32
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: round() for float in C++ Ok suppose I had the number 8.47434 . I want to round it up to 8.5 and to 1 decimal place. How would I go about doing this in C++ 回答1: Multiply by 10 , round and divide by 10 again. Example: round(10 * 8.47434f) / 10; Edit: OK, I just found out that round() is not always present in math.h . The above works in gcc and icl (with Microsoft's libraries), but not in tcc. floor() , however, is

Math inaccuracy in Javascript: safe to use JS for important stuff?

被刻印的时光 ゝ 提交于 2019-12-22 14:41:10
问题 I was bored, so I started fidlling around in the console, and stumbled onto this (ignore the syntax error): Some variable "test" has a value, which I multiply by 10K, it suddenly changes into different number (you could call it a rounding error, but that depends on how much accuracy you need). I then multiply that number by 10, and it changes back/again. That raises a few questions for me: How in accurate is Javascript? Has this been determined? I.e. a number that can be taken into account?

Math inaccuracy in Javascript: safe to use JS for important stuff?

我只是一个虾纸丫 提交于 2019-12-22 14:40:32
问题 I was bored, so I started fidlling around in the console, and stumbled onto this (ignore the syntax error): Some variable "test" has a value, which I multiply by 10K, it suddenly changes into different number (you could call it a rounding error, but that depends on how much accuracy you need). I then multiply that number by 10, and it changes back/again. That raises a few questions for me: How in accurate is Javascript? Has this been determined? I.e. a number that can be taken into account?

How do I round corners of myapp's icon

被刻印的时光 ゝ 提交于 2019-12-22 12:25:10
问题 In simulator mode, my app has an icon with round corners, but on a real iPhone, the corners aren't rounded. 回答1: Corners get automatically rounded if you install via MobileInstallation (from iTunes, Xcode or App Store). If you're building the package and installing it into /Applications manually or with cydia/apt, you have to make a rounded icon yourself. You can find the images used to round the corners and add reflection in /System/Library/Frameworks/UIKit.framework/Other.artwork, the first