Questions tagged [rounding]

Rounding a numerical value means replacing it by another value that is approximately equal but has a shorter, simpler, or more explicit representation.

Rounding a numerical value means replacing it by another value that is approximately equal but has a shorter, simpler, or more explicit representation; for example, replacing £23.4476 with £23.45, or the fraction 312/937 with 1/3, or the expression √2 with 1.414.

5484 questions
3
votes
1 answer

Two rounding methods give different results

Two different rounding methods of floats show different results. "%.2f" % 0.015 # => "0.01" 0.015.round(2) # => 0.02 One is string and the other a float. When rounding anything but 0.5, it rounds correctly or rather the same way as the round…
Lapis
  • 83
  • 6
3
votes
3 answers

SQL Rounding down if x.xx5

Is there a way to round down instead of up where values have .005? E.g. 1.234 -> 1.23 1.235 -> 1.23 1.236 -> 1.24 It's for invoicing purposes. I currently have an invoice which is showing totals of: £46.88 + £9.38 = £56.25 (the Grand total is what…
user3070963
3
votes
2 answers

Using round function in R on very small values returns zero

I sometimes have to deal with very low p values and present them in a tabular format. The values returned by R can have long significance digits (i.e. digits after the decimal point). Now since the p value is anyways so low , I tend to shorten them…
Ashwin
  • 329
  • 1
  • 4
  • 12
3
votes
1 answer

Significant numbers digits of value by its error

I'm in need of a function returning only the significant part of a value with respect to a given error. Meaning something like this: def (value, error): """ This function takes a value and determines its significant accuracy by its…
user3613114
  • 188
  • 8
3
votes
4 answers

How to round to the nearest 0.05?

I'm trying to find a way on how to round to the nearest 0.05 in java. Let's say that I have the following numbers: 0.33 0.02 0.874 0.876 This should become: 0.35 0.00 0.85 0.90 I tried many things and I can only get it to round to n places behind…
n00b1990
  • 1,189
  • 5
  • 17
  • 25
3
votes
2 answers

How to round off if the value is equal to 0.7 up in c#?

I want to round off decimal if the value is 0.7 greater Sample: decimal rate = 3.7 decimal roundoff = 4 decimal rate2 = 3.6 decimal roundoff2 = 3.6 //remain value coz its below 0.7 how can i do that in c#?
comfreakph
  • 549
  • 2
  • 6
  • 20
3
votes
1 answer

Notepad++ Regular Expression "rounding numbers"

I have this in my SVG file: d=" m49.84965,40.23129 l99.5682,19.94812 l0.2192,100.11412 l-100.78656,-19.99842 z" I want to have rounded coordinates: d=" m50,40 l100,20 l0,100 l-100,-20 z"/> The entire document is much larger. I used regex to erase…
Kardaw
  • 371
  • 2
  • 14
3
votes
2 answers

how to convert decimal points?

Possible Duplicate: c# - How do I round a decimal value to 2 decimal places (for output on a page) i have value of 1.564 and 1.565 i need round this value to 1.56 and 1.56,which function suitable for this in c#.
ratty
  • 13,216
  • 29
  • 75
  • 108
3
votes
1 answer

rounding in R cut function

Does anyone know how R chooses the number of significant digits in the cut function? y<-c(61, 64, 64, 65, 66) table(cut(y, breaks=c(60.555, 67.123, 75.055))) produces the result (60.6,67.1] (67.1,75.1] 5 0 but table(cut(y,…
meyerjp3
  • 197
  • 1
  • 3
  • 16
3
votes
2 answers

Force cpp_dec_float to round down

I am using .str(n, std::ios_base::scientific) to print ccp_dec_floats. I've noticed that it rounds up. I am using cpp_dec_float for accounting, so I need to round downward. How can this be done?
user1382306
3
votes
2 answers

PHP to round up to the 2nd decimal place

By calculating areas I have a number which I need to display in a strange way. Always display 2 decimal places. Always round up the 2nd decimal place if the 3rd+ decimal places > 0. Examples: 0.5 = 0.50 0.500003 = 0.51 0.96531 = 0.97 0.96231 =…
Miklos
  • 253
  • 3
  • 13
3
votes
1 answer

Rounding a 3D point relative to a plane

I have a Plane class that holds n for normal and q for a point on the plane. I also have another point p that also lies on that plane. How do I go about rounding p to the nearest unit on that plane. Like snapping a cursor to a 3D grid but the grid…
user3473422
  • 43
  • 1
  • 5
3
votes
2 answers

Rounding up different numbers in Excel

I'm in need of a formula that rounds numbers differently depending on if the number is tens, hundreds, thousands, hundred-thousands, millions, etc. I know the basic rounding functions in Excel but not sure how to do this exactly. Examples: 1 - 999…
TigerXtrm
  • 37
  • 2
  • 6
3
votes
3 answers

How to keep n decimal places in Java

Hi All it might be a trivial question but as for now I could not find any solution.So asking for your help! What I am trying to get is a specific encoding table that looks like this: 0.000 0.100 0.200 I need to keep track of zeroes as I will use…
madbitloman
  • 816
  • 2
  • 13
  • 21
3
votes
4 answers

Is there a way to always round .5 down instead of up using Math.Round?

I am experimenting with the Math.Round class and I am having problems getting it to do what I want it to do. Basically I have the following code: double test = 1.675; double rounded = (double)Math.Round((decimal)test, 2,…
Giardino
  • 1,367
  • 3
  • 10
  • 30