.toFixed() returns a string in JavaScript
Am I missing something here? var someNumber = 123.456; someNumber = someNumber.toFixed(2); alert(typeof(someNumber)); //alerts string Why does .toFixed() return a string? ...
Am I missing something here? var someNumber = 123.456; someNumber = someNumber.toFixed(2); alert(typeof(someNumber)); //alerts string Why does .toFixed() return a string? ...
Hi, Does anyone have a good way to round down a number between 0 and 59 to the nearest 15. I'm using C# 3.5. So ... 1 would be 0 29 would be 15 30 would be 30 etc etc. Many thanks. ...
Both, Borland Pascal 7 and Delphi 2007 have got the procedure STR which takes a number, a length and precision and converts it to a string like this: str(9.234:5:1, s); // -> s = ' 9.2' All is fine if the rounding is non-ambiguous, but if it isn't (0.5 -> up or down?) there is a problem: It seems to depend on the floating point data ...
My database field (sql server 2005) is defined with numeric(15,2). The LINQ 2 SQL generated property is [Column(Storage="_My_Property_Name", DbType="Decimal(15,2)", UpdateCheck=UpdateCheck.Never)] public System.Nullable<decimal> My_Property_Name { get { return this._My_Property_Name; } ...
This problem is killing me. How does one roundup a number UP in Python? I tried round(number) but it round the number down. Example: round(2.3) = 2.0 and not 3, what I would like The I tried int(number + .5) but it round the number down again! Example: int(2.3 + .5) = 2 Then I tried round(number + .5) but it won't work in edge cas...
We are stuck with a database that (unfortunately) uses floats instead of decimal values. This makes rounding a bit difficult. Consider the following example (SQL Server T-SQL): SELECT ROUND(6.925e0, 2) --> returns 6.92 ROUND does round half up, but since floating point numbers cannot accurately represent decimal numbers, the "wrong"...
How would I round the result from two divided numbers, e.g. 3/2 As when I do testOne=$((3/2)) $testOne contains "1" when it should have rounded up to "2" as the answer from 3/2=1.5 ...
Hi all, I have the following code: import java.sql.*; import java.math.*; public class Testd1 { public static void main(String[] args) { System.out.println("Sum of the specific column!"); Connection con = null; int m = 1; double sum, sum1, sum2; int e[]; e = new int[100]; ...
I've seen the following (bizarre) Javascript rounding function in some legacy code. After googling for it I can see that it crops up in a number of places online. However I can't work out why the hard-coded values 8191 and 10485 are present. Does anyone know if there's any sensible reason why these values are included? If not, hopefu...
How to get he upper limit of a number in C? If I divide 3 by 2 I want the answer to be 2 (ie 1.5 rounded to 2). ...
I need to round-off the hours based on the minutes in a DateTime variable. The condition is: if minutes are less than 30, then minutes must be set to zero and no changes to hours, else if minutes >=30, then hours must be set to hours+1 and minutes are again set to zero. Seconds are ignored. example: 11/08/2008 04:30:49 should become 11/...
This feels like the kind of code that only fails in-situ, but I will attempt to adapt it into a code snippet that represents what I'm seeing. float f = myFloat * myConstInt; /* Where myFloat==13.45, and myConstInt==20 */ int i = (int)f; int i2 = (int)(myFloat * myConstInt); After stepping through the code, i==269, and i2==268. What's ...
Well, I am wondering about a thing with rounding decimals, and storing them in DB. Problem is like this: Let's say we have a customer and a invoice. The invoice has total price of $100.495 (due to some discount percentage which is not integer number), but it is shown as $100.50 (when rounded, just for print on invoice). It is stored ...
Using series.add(180, 1); produces a perfectly valid chart like this (little red dot at the bottom with some PolarItemRenderer Mods!) but using series.add(3000/(6000/360), 1); produces this beast: I assume it's because somewhere, 6000/360 = 16.6... is getting rounded? How can I stop this happening? Thanks :) ...
What determines the default setting of the x87 FPU control word -- specifically, the precision control field? Does the compiler set it based on the target processor? Is there a compiler option to change it? Using Microsoft Visual C++ 2008 Express Edition on an Intel Core Duo processor, the default setting for the precision control field...
Is there any way to round numbers in C? I do not want to use ceil and floor. Is there any other alternative? I came across this code snippet when I Googled for the answer: (int)(num < 0 ? (num - 0.5) : (num + 0.5)) The above line always prints the value as 4 even when float num =4.9. Please suggest a solution. ...
I am seeing an intriguing situation rounding Currency in C# (VS 2008 SP1). Below is an image of the test cases: I was expecting cases five, six, and seven (my bad on not numbering them in the output) to round the number up to a penny. Here is my test code: static void Main(string[] args) { decimal one = 10.994m; decimal two...
can anyone explain why I am getting the following results? Dim badDecimal As Decimal = 54.50327999999999 Dim expectedDecimal As Decimal = CDec("54.50327999999999") badDecimal = 54.50328D, while expectedDecimal = 54.50327999999999D. My understanding is that badDecimal should contain the value of expectedDecimal (the fact that expected...
I have a value in the database which is 2.700000002. When I run a query in Management studio in SQL SERVER 2005 I get 2.7. But when I run in SQL SERVER 2000 query analyzer it comes 2.700000002. 2.70000002 is correct why is SQL SERVER 2005 trying to change the value by rounding it or selecting the floor value? ...
Hey all, 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! ...