Menu
  • HOME
  • TAGS

Given a microsecond value , how to accurately get a timeval struct? /*UPDATE GETTING NEGATIVE VALUE*/

c++,timestamp,double,rounding

Something like: timeval to_timeval(double usec) { return { usec / 1000000, usec % 1000000 }; } ...

Rounding small floating point numbers in R

r,rounding

How about ?signif ? (Depending on your application you could also use print(...,digits=3)) vec <- c(1.739362e-08,8.782537e-08,0.5339712) signif(vec,digits=3) ## [1] 1.74e-08 8.78e-08 5.34e-01 print(vec,digits=3) ## [1] 1.74e-08 8.78e-08 5.34e-01 It's fairly hard to get R to format the elements of a vector differently from each other: usually it assumes you want...

How to round a float up on 5 [duplicate]

python,c++,python-2.7,rounding

You can use double rounding to overcome the inability of binary arithmetic to exactly represent a decimal value. round(round(1.265, 3) + 0.0005, 2) ...

Why is rounding done like this? [on hold]

python,python-3.x,rounding

You should have a look at how floats are handled, and what limitations they have. https://docs.python.org/3/tutorial/floatingpoint.html is a Python specific explanation. In your particular example, Python chooses to use a representation that has a limited number of digits (depends on the Python version). Internally, different float values may share the...

Controlling digits / rounding as argument in base functions

r,rounding,rmarkdown,digits

The best way I know is using forward-pipe operator %>% from magrittr package > library(magrittr) > mean(c(0.34333, 0.1728, 0.5789)) [1] 0.36501 > mean(c(0.34333, 0.1728, 0.5789)) %>% round(3) [1] 0.365 I should also mention, that package magrittr is used by another very popular package dplyr, which provides additional functionality for data...

Convert specific Excel forumla to Javascript

javascript,excel,rounding

The second parameter (-1 in your example) specifies to the ROUND function how many digits to use on the approximation. 0 would approximate mathematically to the closest integer. A positive number (n) would approximate using the most n significant digits - ie. ROUND(1.23456, 3) = 1,235 A negative number (-n)...

RoundingMode.HALF_DOWN issue in Java8

java,java-8,rounding,number-rounding

Seems that it's intended change. The JDK 1.7 behavior was incorrect. The problem is that you simply cannot represent the number 10.55555 using the double type. It stores the data in IEEE binary format, so when you assign the decimal 10.55555 number to the double variable, you actually get the...

How to rounding up in oracle

oracle,rounding

If you want to convert given value 2167.12" to "2167.13" Please use this select ceil(2167.124*100)/100 from dual;...

Rounding to 2 decimals

sql,rounding

Cast it as a decimal instead of rounding: CAST((((Sum(case when S.StatType = 'Slot' then S.CashIn - S.CashOut - S.JackPot Else 0 end)*.75)+ (Sum(case when S.StatType = 'Pit' then S.CashIn + S.CreditIn + S.ChipsIn + S.FrontIn - S.CashOut Else 0 end)*.4))/Nullif(Count(Distinct(S.GamingDate)),0)) AS DECIMAL(18,2)) as ADL ...

What is HALF_EVEN rounding for? [closed]

java,rounding,number-rounding

It is useful when you are performing multiple rounding operations and want the cumulative result to be a true average, and not skewed up or down, as it would be with HALF_UP or HALF_DOWN. Specifically, it is useful for statistical analysis (you don't want the results polluted by a non-random...

Simplest Way of Rounding Up the Average in C++

c++,rounding

First of all, make c a double, then use c = (a + b)/2.0 otherwise you have truncation due to division of ints being casted to int. In this way, (a + b) / 2.0 is a double, due to the denominator being a double, so you don't have any...

SQL: Sum a negative and positive real gives wrong value

sql,sql-server,rounding

Why should it be 0? 1.67460317460317 + -1.6746 ------------------- = 0.00000317460317 = 3.17e-06 and the difference between your 3.21 and the "real" math 3.17 is just floating point inaccuracy....

How to round a float value to double value?

java,floating-point,double,rounding,rounding-error

If you know what precision you want you can round it to say 6 decimal places. eg. public static double round6(double x) { return Math.round(x * 1e6) / 1e6; } round6(0.7f) == 0.7 The fact the x passed in was a float doesn't matter provided this precision is suitable....

SQL Server - How to round up or down decimals?

sql,sql-server,select,rounding

You are correct, round is the wrong tool for this job. Instead, you should use floor and ceiling. Unfortunately, they do not have a precision parameter like round, so you'd have to simulate it using division and multiplication: SELECT FLOOR(value * 100) / 100 AS rounded_down, CEILING(value * 100) /...

How to round numbers

python,rounding

Use the built-in function round(), example: >>> round(4.7532,2) 4.75 >>> round(4.7294,2) 4.73 ...

How to do a special type of rounding in excel/vba

excel,vba,rounding

In VBA it is quite simple, since the VBA Round function does that kind of Rounding: Function VBARound(N As Double, Optional NumPlaces As Long = 0) As Double VBARound = Round(N, NumPlaces) End Function The NUMPLACES will allow you to optionally round to other than a whole number....

Efficient way to round n/4 upward

c,algorithm,math,optimization,rounding

If your operand is non-negative, how about: unsigned int roundupdiv4 (unsigned int n) { return (n+3)>>2; } Note that any sensible compiler will compile /4 of an unsigned int as >>2 anyway. I can confirm that by compiling the above with gcc -O3 -S: .file "x.c" .text .p2align 4,,15 .globl...

R by() round stat.desc

r,statistics,rounding

You can explicitly pass the value to the function by defining the FUN=function() value. Using the mtcars dataset library(pastecs) Note that the first line is an abbreviated version of the second by(mtcars$mpg, mtcars$am, stat.desc, norm = TRUE, basic = TRUE) by(mtcars$mpg, mtcars$am, function(X) stat.desc(X, norm = TRUE, basic = TRUE))...

Rounding decimal number upto two decimal places

c#,asp.net,vb.net,rounding

It is rounding correctly but you fail to understand that the value is not the format. There is no difference between the two values, 40000 and 40000.00, and you'll have a similar issue with something like 3.1. Simply use formatting to output whatever number you have to two decimal places,...

MySql - Round upto 10 in ORDER BY Query

mysql,order,rounding

Use arithmetic for this: ORDER BY CEIL(price/10) asc, . . . If you want to see the price rounded up: SELECT CEIL(price/10)*10 EDIT: Round the price down: ORDER BY FLOOR(price/10) asc, views desc, dateadded asc, liked desc, size desc ...

Do rounding errors occur also in floats representing integers?

java,rounding,rounding-error

This is because float is based on floating point notation. In rude words it tries to represent your decimal number as a sum of fractions of power 2. It means it will try to sum 1/2^n1 + 1/2^n2 + 1/2^n3 .... 1/2^nm until gets closes or exact value that you...

How to get a pizza program to round to a full pizza In PYTHON [duplicate]

python,math,rounding

math.ceil rounds up. import math eaters = input("How many people are attending the party?") pieces = input("How many pieces will everyone eat on average?") pizzas = float(eaters) * float(pieces) orders_needed = math.ceil(pizzas/8) print(orders_needed) ...

What is the best way to round numbers in Clojure?

clojure,rounding

You can java interop (Math/(floor|ceil). E.g.: user=> (int (Math/floor (/ 3 2))) 1 user=> (int (Math/ceil (/ 3 2))) 2 ...

How to round smoothly percentage in JS

javascript,math,rounding

try this: function getSmooth(meteo, usage) { meteo = Math.round(meteo*100); usage = Math.round(usage*100); return { evo: (meteo + usage) / 100, meteo: meteo / 100, usage: usage / 100 }; } to test for errors in calculations in evo separate from your visualisation logic: var evo, meteo, usage; // ... //...

Rounding floats in C# WITHOUT using Math.Round

c#,floating-point,rounding

It should be F2 according to MSDN Standard numeric Formatting

HTML text input rounded when numbers entered

html,input,numbers,rounding

If you are working with decimal, the default is DECIMAL(10, 0), you should specify the precision and scale, for example: DECIMAL(10, 4) The declaration syntax for a DECIMAL column is DECIMAL(M,D). The ranges of values for the arguments in MySQL 5.7 are as follows: M is the maximum number of...

How do i rest the variable applied to BigDecimal

java,rounding,bigdecimal

In your code when you are changing rounding methods, you are passing already rounded value to next step. For example, value was rounded by HALF_EVEN to two places and then this already rounded value (2 places) is being passed to FLOOR step and so on. To get behavior you are...

VBA Range.Find function on rounded negative numbers

excel-vba,find,rounding

Having looked at the issues with negative numbers and using it with the find function; a possible solution would be to format your search range and number to find with the same number format. (Based on code supplied by @Gary's Student) Code is below for this. If you don't want...

Round Double to closest 10 (Swift)

swift,double,rounding

You can use the round() function (which rounds a floating point number to the nearest integral value) and apply a "scale factor" of 10: func roundToTens(x : Double) -> Int { return 10 * Int(round(x / 10.0)) } Example usage: println(roundToTens(4.9)) // 0 println(roundToTens(15.1)) // 20 In the second example,...

Why does HALF_UP sometimes round down with double?

java,rounding

There was a bug in Java 8 regarding the NumberFormat and RoundingMod HALF_UP see 8039915. This was fixed with 8u40 (Release Notes).

What's an efficient way to round a signed single precision float to the nearest integer?

floating-point,rounding,msp430

Conversion by bit operations is straightforward, and is demonstrated by the C code below. Based on the comment about the data types on the MSP430, the code assumes that int comprises 16 bits, and long 32 bits. We need a means of transferring the bit pattern of the float to...

Count amount of decimal places (Swift)

swift,calculator,rounding

Try: let s1 = String(format: "%.19g", 1.2345) // 1.2345 Not sure if swift printf supports '%g' though. Edit: the 19 is based on the precision of a double, to display all (nonzero) digits, but not get ...0001 at the end. '%g' is the printf format specifier for 'natural' representation of...

Java Dealing with Double values having E [closed]

java,string,math,rounding,number-formatting

use BigDecimal. 1 java doc BigDecimal bd = new BigDecimal("String") ...

What is the cleanest way to round a value to nearest 45 degrees?

language-agnostic,rounding

I'd divide the value by 45°, round, and then multiply back by 45°. Pseudocode: deg = round(deg / 45) * 45; Assumption: the / operator returns a floating-point representation and does not perform integer division. If the specific language does not treat it like this it should be handled explicitly...

Parsing JSON rounds Negative Values

c#,json.net,rounding

Some code to Andrew's correct answer: var settings = new JsonSerializerSettings(); settings.FloatParseHandling = FloatParseHandling.Decimal; string json = @"{ ""rings"" : [ -9221300.3411999997, 4120326.8838 ] }"; var rss = JsonConvert.DeserializeObject(json, settings); ...

How is default rounding in divison handled?

rounding,cobol

COBOL does no rounding, unless you tell it to. What it does do, if you don't tell it to do rounding, is low-order truncation. Some people may prefer to term that something else, it doesn't really matter, the effect is the same. Truncation. Negative values are dealt with in the...

MySQL database updates to the round decimal

python,mysql,decimal,rounding,mysql-python

The number column in the Testing database table apparently has an integer data type. You can check the data type by querying EXPLAIN Testing. If it has an integer data type, the number value is coerced to an integer before it stored in the table. If you wish to store...

Java, MySQL or PHP - rounding down minutes to the next 10 minutes [closed]

java,php,mysql,datetime,rounding

Here is an answer from the following stackoverflow post : How to round a time to the nearest 15 minute segment SELECT FROM_UNIXTIME( TRUNCATE(UNIX_TIMESTAMP(NOW()) / 900,0)*900); Credits to Gavin Towey! Just replace 900 (15 mins) with 600 (10 mins)....

C++ rounding behavior

c++,linux,g++,rounding

Your computer can't represent most decimal fractions numbers exactly, since it works with binary numbers. Instead, it tries to find the closest number it can represent, and use that instead. For instance, my computer represents the following numbers as: decimal actual representation 0.115 0.115000002 0.225 0.224999994 0.245 0.245000005 0.335 0.335000008...

How can I change a var to the nearest number? [duplicate]

javascript,rounding

How about this? z = (Math.abs(z-x1)<Math.abs(z-x2))?x1:x2; If you're sure x1 < x2, then: z = ( (z-x1) < (x2-z) ) ? x1 : x2; ...

How to do custom rounding of numbers in Java?

java,rounding

Math.floor(x+0.7) should do it. This should work for an arbitrary mantissa. Just add the offset to the next integer to your value and round down. The rounding is done by floor. Here is what the java API says to floor: Returns the largest (closest to positive infinity) double value that...

Custom round number function

r,function,rounding

You probably want signif which rounds off to a given number of significant digits. x <- runif(16) * 10^(7*runif(16)-5) cbind(x, mx = my.func(x), sx = signif(x, 3)) x mx sx [1,] 1.395044e-01 1.40e-01 1.40e-01 [2,] 9.751368e-06 9.80e-06 9.75e-06 [3,] 3.451619e-04 3.50e-04 3.45e-04 [4,] 2.203204e-03 2.20e-03 2.20e-03 [5,] 6.660684e-05 6.70e-05 6.66e-05...

random rounding

php,random,rounding

function myround($a, $b) { $d = $a * $b / 100.0; $f = floor($d); if ((rand() / getrandmax()) > ($d - $f)) return $f + 1.0; return $f; } ...

Nearest multiple of a power of two fraction

java,double,rounding

If you want to chose the power of two, the simplest way is to multiply by e.g. 16, round to nearest integer, then divide by 16. Note that division by a power of two is exact if the result is a normal number. It can cause rounding error for subnormal...

Excel formula for working with multiples

excel-formula,rounding,worksheet-function

It's worth noting that Excel has built-in functions for working with multiples: CEILING and FLOOR (in newer versions you have CEILING.MATH and FLOOR.MATH). In your case, this should work: =CEILING(A1,20)-A1 ...

round() returns redundant amount of decimals

php,rounding,precision,floating-point-precision

There is no need to replace round with number_format. You could use round with the flag to round down. Choose what is best for the application. Are you rounding a float? Use round Are you wanting to format a number and group by thousands? Use number_format <?php $number = '0.5600';...

Rounding numbers to two decimal places in Java

java,rounding,number-rounding

I would test the distance with the standard rounding, then adjust and round again : for (String string : new String[] {"1.1245", "1.1244", "1.1235", "1.1249", "1.1299"}) { BigDecimal a = new BigDecimal(string); if (a.setScale(2, BigDecimal.ROUND_HALF_UP).subtract(a).compareTo(new BigDecimal("-0.0044")) < 0) { System.out.println(string + ":" + a.add(new BigDecimal("0.001")).setScale(2, BigDecimal.ROUND_HALF_UP)); } else { System.out.println(string...

Explanation of JavaScript Decimal Rounding example at MDN?

javascript,rounding,tostring

The e is the exponential symbol in scientific notation, you get it in toString() when the number is really big (or small). For example 0.0000000000001 yields 1e-13. As for the other part of your question: The method is applicable also when there is no exponential part. In this case the...

JavaScript Zero Bitwise Left-Shift and Right-Shift Equivalent in Python?

javascript,python,bit-manipulation,rounding,floor

just cast the float to an int int(2.667) it will always floor/truncate the float once the float is non negative if you have negative numbers you do want to floor not just truncate use math.floor . In [7]: int(2.667 ) Out[7]: 2 In [22]: from math import floor In [23]:...

Is it possible to use BASH/bc/printf to round a float to it's first significant figure?

bash,math,printf,rounding,bc

The following will truncate your numbers to the first non 0 digit: grep -o "0.0*." <<< "$NUMBER" For example: grep -o "0.0*." <<< "0.000003243322" Prints: 0.000003 ...

BigDecimal 1.0E+8 / 100000000 with ROUND_HALF_UP is 0

java,rounding,bigdecimal,divide

It all has to do with the scales of the BigDecimals involved. When you specify exponential format in the constructor that takes a String, the scale may be negative. This indicates that the significant digits don't extend all the way down to unity. BigDecimal oneEPlus8 = new BigDecimal("1.0E+8"); System.out.println(oneEPlus8.scale()); This...

Why does a cast from int to float round the value?

c,casting,int,rounding

I'm assuming that by float you mean a 32-bit IEEE-754 binary floating point value, by double you mean a 64-bit IEEE-754 binary floating point value, and by int you mean a 32-bit integer. Why does this happen? The range of float far exceeds that of int Yes, but the precision...

“(int)Math.ceil(double)” always return 1 when values is greater than 0

java,casting,int,double,rounding

In all the outputs you printed (except the first one which is 0) Speed is smaller than 1 (7.026718463748694E-4, 5.27003884781152E-4, etc...). Notice the negative exponent. Therefore it's no wonder ceil returns 1....

Round Off in PHP

php,rounding

You can use floor() to round down: $number = 1.399; $roundedNumber = number_format(floor($number * 100)/100, 2); echo $roundedNumber; //Returns 1.39 ...

why does _mm_mulhrs_epi16() always do biased rounding to positive infinity?

rounding,sse

A most serious mistake. I asked the same question on the Intel developer forums and andysem corrected me, pointing out the behavior is to round to the nearest integer. I was mistaken into thinking it was biased because the formula from MSDN, https://msdn.microsoft.com/en-us/library/bb513995.aspx was (x * y + 16384) >>...

Math rounding up (solved) [closed]

c#,rounding

public static int Round(double number) { int numberLenght = number.ToString().Length; int times = (int) Math.Pow(10, numberLenght-2); return (int) (number*times); } You something like this?...

How to show number of asterisks to nearest thousand?

java,rounding

use bar1 = (store1+500)/1000; System.out.print("Store 1: "); for(int i = 1; i <= bar1; i++) System.out.print("*"); ...

round() mode ROUND_HALF_UP with PHP 5.2.17

php,rounding

... learn math: $val = intval($var / 50)*50+50; ...

Geometry rounding problems: object no longer convex after simple transformations

c++,geometry,rounding,cgal,convex

In the end I discovered the root of this problem was the fact that the convex hull contained lots of triangles, whereas my input shapes were often cube-shaped, making each quadrilateral region appear as 2 triangles which had extremely similar plane equations, causing some sort of problem in the algorithm...

How do I specify the rounding mode for floating point numbers?

floating-point,rust,rounding

It appears that the implementation of Float::round, at least for f32 and f64, forward to the roundf32/roundf64 instrinsics, which themselves are implemented using the LLVM functions llvm.round.f32 and llvm.round.f64. The documentation for llvm.round.* doesn't say anything about how to control the rounding mode, sadly. There doesn't appear to be anything...

Doubles from ViewModel get rounded to ints in javascript array

javascript,arrays,razor,rounding,asp.net-mvc-viewmodel

Float values passed to JavaScript as JSON or direct values must have "." as decimal separator. Some cultures use "," and thus parsing of such numbers as JSON or with parseFloat will fail to recognize decimal part. Fix: use invariant culture to format numbers or use existing libraries (like Json.Net)...

Subsetting Outliers from a data frame by using the results of a boxplot diagram

r,subset,rounding

geom_boxplot calls boxplot.stats to calculate the positions of the upper and lower whiskers. You can do it too: > boxplot.stats(v) $stats [1] 93.340 96.069 97.876 99.087 100.359 $n [1] 24 $conf [1] 96.90265 98.84935 $out [1] -234.347 75.764 (v is assumed to be your input data vector): From the boxplot.stats...

Precision, Rounding, and data types in XSLT2.0

xslt,decimal,rounding,xslt-2.0,data-type-conversion

Assuming there is no schema involved, the typed value of the element InvoiceAmount is xs:untypedAtomic - which essentially means a string, but one that adapts itself to the context in which it is used. If you do an explicit conversion to xs:decimal, the untypedAtomic value "-62.84" will convert exactly. If...

Problems rounding large figures using ng-currency

angularjs,rounding,currency

From your plunker I see you are mixing versions: From https://github.com/aguirrel/ng-currency#versions Versions If you use angular 1.2.x please, use 0.7.x version. If you use angular 1.3.x or above just use 0.8.x version instead. Please, use https://rawgit.com/aguirrel/ng-currency/v0.8.x/src/ng-currency.js instead of uploaded ng-currency.js in you plunkr. <script src="https://rawgit.com/aguirrel/ng-currency/v0.8.x/src/ng-currency.js"></script> You can see it in...

The same (int)doubles round up and down in Java

java,int,double,rounding,mouselistener

Java is doing some hidden casts. Depending on which variable is a double or an int, you might get unexpected results because some double values have been casted to ints. I would make sure all your variables are doubles. Also, do not forget that floating points also have representation limitations,...

How to get 1 digit interger number in a double number in Postgres SQL?

postgresql,int,rounding

trunc function will truncate number to given number of decimals: select trunc(2.7, 0); trunc ------- 2 (1 row) ...

Perl5 formline round down the exact value 0.5 not round up

perl,rounding

In the absence of a concrete demonstration, I shall point out the two likely culprits: "We normally should round up" is absolutely false. There are many different rounding system. sprintf, for example, uses round-to-even. $ perl -E'say sprintf "%1\$.1f => %1\$.0f", $_ for 3.5, 4.5, 5.5, 6.5' 3.5 => 4...

Is Cross-Platform Double Math Determinism Possible with Rounding?

double,cross-platform,rounding,precision,deterministic

I've actually been thinking about the whole matter in the wrong way. Instead of trying to minimize errors with greater accuracy (and more overhead), I should just use a type that stores and operates deterministically. I used the answer here: Fixed point math in c#? which helped me create a...

How to round to zero decimals if there is no decimal value with Jinja2?

python,templates,flask,rounding,jinja2

You can use string filter, then use str.rstrip: >>> import jinja2 >>> print(jinja2.Template(''' ... {{ (1.55555|round(2)|string).rstrip('.0') }} ... {{ (1.5|round(2)|string).rstrip('.0') }} ... {{ (1.0|round(2)|string).rstrip('.0') }} ... {{ (1|round(2)|string).rstrip('.0') }} ... ''').render()) 1.56 1.5 1 1 NOTE Using str.rstrip, you will get an empty string for 0. >>> jinja2.Template('''{{ (0|round(2)|string()).strip('.0') }}''').render()...

“width: calc(100% / 3);” not working properly in any IE

css,internet-explorer,width,rounding,calc

It would seem that the suggestion by @web-tiki with: width:33.33%; is the best option....

Calculate RTT with 3 decimal places in Python 3

python,python-3.x,time,rounding,decimal-point

Use the second argument of round which indicates the number of numbers after the decimal: send_time_ms = time.time() ... recv_time_ms = time.time() rtt_in_ms = round(recv_time_ms - send_time_ms, 3) ...

Round number in java and add separator

java,rounding,separator

If you overwrite the standard format with #.00 you have no grouping seperator in your format. For your expected case you have to include the grouping seperator again into your custom format: DecimalFormat theFormatter = new DecimalFormat("#,###.00", theSymbols); The pattern definition symbols can be found in the Doc...

Half-Even Rounding

java,rounding

I'm not certain this is actually technically a bug. The issue is that when you write 4.45 and the value is interpreted as a double, that is rounded to a binary fraction: a sum of multiples of powers of 2, to some precision. (That rounding itself is done with HALF_EVEN...

PHP round precision bug?

php,rounding

round will take care of the precision if that digit is not 0 as the last 0 has no effect in any mathematical operation. If the number is 1.569 then round will return 1.57 If you want that 0 the you can use - number_format(58.900662, 2, '.', ','); number_format()...

Development of a windows form-based application to calculate the area and boundary lengths for Circles, Squares and Right-Angled Triangles [closed]

c#,visual-studio,radio-button,rounding,shapes

I think this could be your problem. In your method: private void trackBar1_Scroll(object sender, EventArgs e) You are declaring new variables called Area and Length and not using the class variables which you are using when rounding the values. Try write your calculations without the type before Area and Length....

How does Python babel round numbers?

python,decimal,rounding,currency,babel

If you follow the code through to apply you can see a reference to a bankersround procedure, which tells us what we need to know. Babel is using the bankers round method of rounding, which rounds to the nearest even number on 5. So, .245 and .235 round to .24...

Java: double rounding algorithm

java,floating-point,rounding

Floating-point numbers don't have decimal places. They have binary places, and the two are not commensurable. Any attempt to modify a floating-point variable to have a specific number of decimal places is doomed to failure. You have to do the rounding to a specified number of decimal places after conversion...

Why do I have a decimal error when writing data to MS Access via Matlab?

matlab,ms-access,rounding,numeric

Rounding a trailing 0 (zero) is not rounding. What you miss is the format that displays the number. Where you do this, set number of decimals to two....

Math.round MidPointRounding.AwayFromZero in javascript

javascript,c#,math,rounding

If you know that you are going to be diving by 100, you can just round first then divide: var round = Math.round(value)/100; //still equals 172.45 However, if you don't know what you are going to be diving with, you can have this more generic form: var round = Math.round(value/divisor*100)/100;...

PHP Round With Decimal & Comma $1,000

php,rounding,number-formatting

First do an equation, than round and as the last one thing use number_format. echo number_format(round($vehicle->prices['total_rental'] * .5, 2), 2, '.', ','); ...

EXCEL - incorporating ROUND to IF statement

excel,if-statement,excel-formula,rounding

MANY THANKS to JNevill =IF(B4>0,MROUND((((B4-B5)/2)+B5)+B7+IF(E8>0,E8)+IF(B8="yes",B7)+B9,.0625)," ") https://support.office.com/en-ie/article/MROUND-function-86dc90eb-1e0e-4e03-8913-6debe3f18c5f However, this only rounded to the nearest (which is what I asked for) and not always up . I believe =CEILING() is more of what I was needing for because it is rounding to the next highest 1/16. =IF(B4>0,CEILING((((B4-B5)/2)+B5)+B7+IF(E8>0,E8)+IF(B8="yes",B7)+B9,0.0625)," ")...

Python style round() in Java

java,python,rounding

One possible way: public static long symmetricRound( double d ) { return d < 0 ? - Math.round( -d ) : Math.round( d ); } If the number is negative, round its positive value, then negate the result. If it's positive or zero, just use Math.round() as is....

Replace “Lunch Out, Lunch In” with duration in formula to give Time Out/In difference excluding Lunch

excel,excel-formula,rounding,worksheet-function,time-format

Adding a ColumnE for Lunch, please try: =IFERROR(IF(D2="","",(D2-A2)*24)-E2,"") formatted as number....

Rounding a number while using string formatting in python

python,string,formatting,rounding

Well, you could always round the return statement. So, round(payment, 2) for example. And, I am not sure why you are using \r. (Could you tell me why?). You could do %.2f to use two decimal places instead.

Why won't SQL round correctly from my batch script?

sql,sql-server-2008,batch-file,rounding

Operator / is type-specific, so you should cast your integer to the float, like this: ROUND(CAST(($Var3) AS float) / 6000), 2) or use the division by float, like this: ROUND(($Var3 / 6000.0), 2) Returns the data type of the argument with the higher precedence. For more information, see Data Type...

Round to whole numbers without using conditional statements in Python - Logic

python,logic,rounding,number-rounding

This is a weird restriction, but you could do this: x = str(x) dec_index = x.find('.') tenth_index = dec_index + 1 tenth_place = x[tenth_index] # will be a string of length 1 should_round_up = 5 + tenth_place.find('5') + tenth_place.find('6') + tenth_place.find('7') + tenth_place.find('8') + tenth_place.find('9') print int(x[0:dec_index]) + should_round_up What...

Rounding user input in form using JavaScript

javascript,jquery,regex,rounding

RegEx Let's start with your RegEx. What you have will match decimal numbers with any number of decimal places, but also other things. ^((?:\d+(?:\.\d*)?)|(?:\.\d+))$ Explanation First of all we declare that if there is only an integer without decimal places, that's fine. However, we also allow the short hand .8...

Rounded tabs focused border

tabs,javafx,focus,rounding

If you have a look at modena.css file, for the selected tab pseudoclass, there is this rule for the border radius: .tab-pane:focused > .tab-header-area > .headers-region > .tab:selected .focus-indicator { -fx-border-radius: 2, 1; /* looks sharper if outer border has a tighter radius (2 instead of 3) */ } You...

php round a number [duplicate]

php,variables,rounding

number_format() should do the trick. // english notation without thousands separator $amount2 = number_format($amount2, 2, '.', ''); // 1234.57 ...

.NET Micro framework Rounding

c#,rounding,.net-micro-framework

You can try Multiplying your value by 100, round and then divide the result by 100.

PHP: number_format rounding

php,floating-point,rounding

Not the rounding makes it -0. The $round variable contains this before the last line: string(3) "0.0" You can verify this with adding this line: var_dump($round); before the echo. So if you multiply "0.0" (string) with -1 then the result will be "-0" Because (string)0 is casted to (float)0 before...

Imitate Math.Round for GnuMP library in C#

c#,rounding

Today I found an mathematically correct answer: public static Real Round(Real r, int precision) { Real scaled = Real.Pow(10, precision + 1); Real multiplied = r*scaled; Real truncated = Trunc(multiplied); Real lastNumber = truncated - Trunc(truncated/10)*10; if (lastNumber >= 5) { truncated += 10; } truncated = Trunc(truncated/10); return truncated...

Can someone please explain this JavaScript decimal rounding function in detail?

javascript,function,rounding,deciphering

eX is a valid part of a Number literal and means *10^X, just like in scientific notation: > 1e1 // 1 * Math.pow(10, 1) 10 > 1e2 // 1 * Math.pow(10, 2) 100 And because of that, converting a string containing such a character sequence results in a valid number:...