numbers

Opposite of Number.toExponential in JS

亡梦爱人 提交于 2019-11-28 11:19:21
I need to get the value of an extremely large number in JavaScript in non-exponential form. Number.toFixed simply returns it in exponential form as a string, which is worse than what I had. This is what Number.toFixed returns: >>> x = 1e+31 1e+31 >>> x.toFixed() "1e+31" Number.toPrecision also does not work: >>> x = 1e+31 1e+31 >>> x.toPrecision( 21 ) "9.99999999999999963590e+30" What I would like is: >>> x = 1e+31 1e+31 >>> x.toNotExponential() "10000000000000000000000000000000" I could write my own parser but I would rather use a native JS method if one exists. Gene Pavlovsky The answer is

Javascript function need allow numbers, dot and comma

时间秒杀一切 提交于 2019-11-28 11:02:01
I need to create a function to allow numbers dot and comma. So anyone corrects the following function function on(evt) { var theEvent = evt || window.event; var key = theEvent.keyCode || theEvent.which; key = String.fromCharCode( key ); var regex = /[0-9]|\./; if( !regex.test(key) ) { theEvent.returnValue = false; if(theEvent.preventDefault) theEvent.preventDefault(); } } Firstly your regex currently doesn't allow comma, which is your requirement. Secondly, you haven't used any quantifier, so your regex will match only a single character - one of [0-9] or a dot . You need to use a quantifier.

Sorting strings containing numbers in a user friendly way

微笑、不失礼 提交于 2019-11-28 10:48:05
Being used to the standard way of sorting strings, I was surprised when I noticed that Windows sorts files by their names in a kind of advanced way. Let me give you an example: Track1.mp3 Track2.mp3 Track10.mp3 Track20.mp3 I think that those names are compared (during sorting) based on letters and by numbers separately. On the other hand, the following is the same list sorted in a standard way: Track1.mp3 Track10.mp3 Track2.mp3 Track20.mp3 I would like to create a comparing alogorithm in Delphi that would let me sort strings in the same way. At first I thought it would be enough to compare

How to Compare Two Numbers in Java? [duplicate]

断了今生、忘了曾经 提交于 2019-11-28 10:46:06
Possible Duplicate: Comparing the values of two generic Numbers I would like to compare two arbitrary instances of Number to find out which is greater. As you know, those may be Integers, Longs or Doubles but also BigIntegers or BigDecimals. So what to do? Number does not implement Comparable . Can't use doubleValue() as there might be a loss of precision from BigDecimals or BigIntegers. Do I really have to go into instance-testing and casting? There must be some library that does this. But I've already checked Apache Commons and Guava with no luck. Edit 1: Comments pointed this out: Comparing

Rounding numbers in Sass and adjusting the amount of decimals

旧街凉风 提交于 2019-11-28 10:18:01
Is their a way in sass to change the digit that rounding occurs on, I would like to stop rounding of a number like this 2.0242914979757085% to this 2.024%. I would like to adjust the amount of decimals in the output css From the SASS change logs: The numeric precision of numbers in Sass can now be set using the --precision option to the command line. Additionally, the default number of digits of precision in Sass output can now be changed by setting Sass::Script::Number.precision to an integer (defaults to 3). Since this value can now be changed, the PRECISION constant in Sass::Script::Number

Converting Words to Numbers in Java

北战南征 提交于 2019-11-28 10:10:50
I have seen a lot of algorithms in which you give them a number say "123" and it converts it to One hundred twenty three. But i can't seem to find something that does the opposite, and the ones i did find only do it up to the number 1000, can anyone direct me in the correct way as what i could do to create a method that takes "One thousand two hundred and thirty four" and gives back "1234" I hope below code will do the job in most of the cases. However some modification might be required as I've not tested properly yet. Assumption: Positive, negative, plus, minus is not allowed. Lac, crore is

How can I generate a random number within a range but exclude some?

▼魔方 西西 提交于 2019-11-28 09:57:02
Basically I pick a random number between 0-24: Math.floor(Math.random() * myArray.length); // myArray contains 25 items Lets say it comes out to be 8. Now I want to get another number in the same range 0-24 but this time, I do not want an 8. The next time, I might roll a 15. Now I want to roll again but I don't want an 8 or 15. The way I am handling this now is by using do while loops and if the number comes out the same, I just reroll. This is a small portion of my homework and I, in fact, have it working to meet all the requirements so I guess you could say this is for my own personal

Select values that begin with a number

旧城冷巷雨未停 提交于 2019-11-28 09:45:50
I have a table with a column containing data that begin with numbers too, on MySQL How can I select the rows that begin only with a number? SELECT * FROM YourTable WHERE YourColumn regexp '^[0-9]+' You can do: SELECT * FROM MyTable WHERE MyColumn REGEXP '^[0-9]'; The regular expression used is ^[0-9] . ^ - Start anchor, used to ensure the pattern matches start of the string. [ - Start of character class. 0-9 - Any digit ] - End of character class Effectively we are trying to select those values in the column that begin with a digit . Demo: mysql> select * from tab; +-------+ | col | +-------+

Make big and small numbers human-readable [duplicate]

前提是你 提交于 2019-11-28 09:42:20
This question already has an answer here: Formatting Large Numbers with .NET 5 answers I would like to print my very small numbers in C# in a human friendly way, such as: 30µ for 3E-5 or 456.789n for 0.000000456789 . I know of the Humanize_number () function from BSD in C, but only compatible with bit ints, not floats and doubles. Is there the equivalent in C# that supports those? Also, it should keep a certain amount of precision when displaying numbers, like: 0.003596 should be displayed as 3.596µ , not 3.6µ (or worse, 4µ ). The possible answer here: Formatting Large Numbers with .NET but

Why does Array.filter(Number) filter zero out in JavaScript?

依然范特西╮ 提交于 2019-11-28 09:35:32
I'm trying to filter all non-numeric elements out from an array. We can see the desired output when using typeof. But with Number, it filters zero out. Here's the example (tested in Chrome Console): [-1, 0, 1, 2, 3, 4, Number(0), '', 'test'].filter(Number) // Which output with zero filtered out: [-1, 1, 2, 3, 4] // 0 is filtered If we use typeof, it doesn't filter zero, which was expected. // code [-1, 0, 1, 2, 3, 4, Number(0), '', 'test'].filter(n => typeof n === 'number') // output [-1, 0, 1, 2, 3, 4, 0] My question: What is the difference between the 'Number' and 'typeof' approaches? Number