numbers

Can someone explain to me NaN in Ruby ?

I just found a bug in some number manipulations in my program and I'm getting a FloatDomainError (NaN) So I started logging the number passed in with: if(metric.is_a?(Numeric)) self.metric = metric else LOGGER.warn("metric #{metric} is not a number") self.metric=0 end But the number being passed in is NaN which apparently is_a?...

Conditional Formatting iwork Numbers

Hi, I am trying to create a spreadsheet in iwork 09 Numbers. I have values in cells along with dates, however until this date is passed I don't want the corresponding value to be included in the final "total" formula which adds all the values together. Below is the formula for one of the cells, this works fine but it shows the cell va...

C#: How to detect which textbox value is equal to, or the closest to zero of a group of textboxes/values?

I have a great excel formula I have been using but I want to distribute something a little more substantial and durable and also user friendly to my group of designers at work. I am also dealing with negative numbers unfortunately so going by the minimum value would not work. So if textbox1 said 13, textbox2 said 4, and textbox3 said -...

Cocoa/Objective C: Convert numbers to strings using Japanese unicode characters

Converting numbers to strings is no problem, but the string created uses ascii numbers. I am inserting the number in a Japanese sentence. The character itself is correct, say 3, for example, but the width and positioning should be a little different when typing in Japanese. As a result the number looks cramped up against the following ch...

android NumberFormat

Here is my code : NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(14); nf.setMinimumFractionDigits(0); double d = 0; System.out.println(nf.format(d)); With Android SDK : it prints "0.00000000000001" With Java SDK (j2SE) : it prints "0" Why this difference ? bug in NumberFormat class for Android SDK ? ...

Interview Question, What do they want to accomplish?

I was on a technical job interview today, and it was time to give me some programming exercises. I finally came to the last question: Given the numbers: 116 104 105 115 32 105 115 32 99 111 114 114 101 99 ? What is the next number? To really understand my mindset, I encourage you to stop reading, and really try to figure out what th...

how can I check the input is only number and white space in regular expression?

I have "222 22 222", "333 33 33 333", "1234/34", and "ab345 543" and I want to check whether these inputs are numeric and white space. I.E this case, the first and the second inputs should return True by using method Test of Regular Expression, or return its own value by using Exec method. The third and the fourth should return false. Ho...

How can I format a String number to have commas and round?

What is the best way to format the following number that is given to me as a String? String number = "1000500000.574" //assume my value will always be a String I want this to be a String with the value: 1,000,500,000.57 How can I format it as such? ...

How to format long numbers?

If I have a number that is 100,000,000 how can I represent that as "100M" in a string? ...

double to string formatting

Hi, I have a Double value xx.yyy and I want to convert to string "xxyyy" or "-xxyy", if the value is negative. How could I do it? Regards. ...

How did a float turn into a double here?

Edit: As always, great answer in under 5 minutes :) Turns out if I make a tiny change - make the F capital in "float", I'll get the output I expected. class NumberMachine{ public static void main(String [] args) { Integer wi1 = new Integer("420"); int i = 101; Integer wi2 = i*420/101; if(wi1 == wi2)...

How can I parse a numeric operation containing +,-,*,/ and parentheses and return the result?

Possible Duplicate: Best algorithm for evaluating a mathematical expression? I mean like when you enter this in Delphi: var i : integer; begin i=5 + 5 + (2 * (3 + 2)) + (1 * 4 + (1 - 3)) end; But I want a command that works in this way: var i : integer; s:string; begin s:='5 + 5 + (2 * (3 + 2)) + (1 * 4 + (1 - 3))'; ...

C++ Coprimes Problem. Optimize code.

Hi i want to optimize the following code. It tries to find all coprimes in a given range by comparing them to n. But i want to make it run faster... any ideas? #include <iostream> using namespace std; int GCD(int a, int b) { while( 1 ) { a = a % b; if( a == 0 ) return b; b = b % a; if( b == 0 ) retur...

Retrieving the actual binary value of a JavaScript number value?

In JavaScript, for a given property containing a Number value, is it possible to retrieve the actual binary value - the 64 bits representing the value. var x = 13; What 64 bits are stored in the memory location that x points to? I know that there are IEEE 754 converters out there. But is it possible to retrieve the actual live binary ...

The dot after the integer number value in JavaScript?

In JavaScript it is valid to end an integer numeric literal with a dot, like so... x = 5.; What's the point of having this notation? Is there any reason to put the dot at the end, and if not, why is that notation allowed in the first place? UPDATE: Ok guys, since you mention floats and integers... We are talking about JavaScript here...

convert number to decimal in php

Hi guys, I have a number stored in a variable. The number is pulled from the database as 9900..I need to convert this number to 99.00 in order to display to a customer in HTML. I was wondering how can I achieve this in php. Thanks. ...

Linux number of files in directory curiosity

Just out of curiosity, is there any method in Linux to know the number of files in a directory in O(1) (independently of the number of files) without having to list the directory first? I'm searching for an alternative to ls | wc -l. Thanks! ...

Divide and round

$number = some number; When I divide this number, it gives not a round value. Can give something like 3.13. How to round it to the biggest value? Like: if ($number == 3.5) { $number = 4; } elseif ($number = 3.51) { $number = 4; } else if ($number == 3.49) { $number = 3; } ...

Convenience methods for Ruby's Number class and 0.

I'm writing convenience methods to check if number is positive or negative like so: class Numeric def positive? self > 0 end def negative? self < 0 end end but in this case I do not know how to handle cases like these: >> 0.positive? >> 0.negative? Update: I've updated the typo in the class name. I used numeric bec...

Biggest number in computer ever

Just asked by my 5 year old kid: what is the biggest number in the computer? We are not talking about max number for a specific data types, but the biggest number that a computer can represent. Infinity is not allowed. UPDATE my kid always wants to print as well, so lets say the computer needs to print this number and the kid t...