numbers

Skewing java random number generation toward a certain number

不羁岁月 提交于 2019-11-30 02:54:12
问题 How, in Java, would you generate a random number but make that random number skewed toward a specific number. For example, I want to generate a number between 1 and 100 inclusive, but I want that number skewed toward say, 75. But I still want the possibility of getting other numbers in the range, but I want more of a change of getting numbers close to say 75 as opposed to just getting random numbers all across the range. Thanks 回答1: Try http://download.oracle.com/javase/6/docs/api/java/util

why are arabic numbers (١٢٣) not accepted in textboxes as real numbers?

谁说胖子不能爱 提交于 2019-11-30 01:48:29
问题 while developing one of my sites, i noticed that if I enter arabic numbers (١٢٣), they are not interpreted as real number values. Then, I tested a few other sites only to find that they also don't accept arabic numbers. The problem is, my client seems to require this functionality (accepting arabic numbers).. and I have no idea where to start. My platform is magento (php). 回答1: To allow PHP to accept the Arabic numbers or Persian numbers (Farsi) (١٢٣٤٥), I developed this easy function: <?php

Rounding up to the second decimal place [duplicate]

淺唱寂寞╮ 提交于 2019-11-30 01:19:53
Possible Duplicate: PHP Round function - round up to 2 dp? What my problem is: When i use ceil(3.6451895227869); i get like 4 but i want 3.65 Can you help me out? UPDATE Please remember: This should always round to ceil like while rounding 3.6333333333333 it must not be 3.63 but should be 3.64 Check out http://www.php.net/manual/en/function.round.php <?php echo round(3.6451895227869, 2); ?> EDIT Try using this custom function http://www.php.net/manual/en/function.round.php#102641 <?php function round_up ( $value, $precision ) { $pow = pow ( 10, $precision ); return ( ceil ( $pow * $value ) +

JavaScript Number.toLocaleString() with 4 digits after separator

帅比萌擦擦* 提交于 2019-11-30 00:06:38
问题 Is there a way to get number.toLocaleString() with 4 digits after the comma? Example: var number = 49.9712; document.getElementById('id').innerText = number.toLocaleString(); Result: 49,9712 But now it always returns number with 2 digits after comma: 49,97 回答1: You may use second argument to provide some options. In your case, with default locale: number.toLocaleString(undefined, { minimumFractionDigits: 4 }) 回答2: I found that var number = 49.9712; number.toLocaleString( {

Finding an item of an array of numbers without using a loop

眉间皱痕 提交于 2019-11-29 23:31:08
问题 This is a stupid question, it feels like one. But mental block is bad right now. :( My problem is I have an array consisting only of numbers. I want to use that array as a lookup, but the number I pass to lookup a number in the array keeps looking to the array in the index of that number, not whether that number exists in the array. For example: var a = [2,4,6,8,10], b = 2; if(a[b]){ /* if the number 2 exists in the array a, then do something * } But that looks at the array value in position

Algorithm in C - playing with numbers - number with 3 in units place

隐身守侯 提交于 2019-11-29 23:16:08
I came across this question in an interview. Any number with 3 in its units position has at least one multiple containing all ones. For instance, a multiple of 3 is 111, a multiple of 13 is 111111. Given a number ending in 3, I was asked the best method to find its multiple containing all 1's. Now a straightforward approach is possible, where you do not consider space issues but as the number grows, and sometimes even if it doesn't, an int (or a long int at that!) in C cannot hold that multiple. What is the optimal way to implement such an algorithm in C? Bolo UPDATE : Incorporating Ante's

Converting number abbreviations (5.2k, 1.7m, etc) into valid integers with PHP

人走茶凉 提交于 2019-11-29 20:05:37
问题 I have a database with a column containing a variety of numbers written in "shorthand", for example: 5k for 5,000 86.6k for 86,600 4.1m for 4,100,000 1.2b for 1,200,000,000 I'd like to do some calculations with these numbers for a PHP frontend, but I need to convert them into valid integers in order to do so. How could I do this with PHP? 回答1: Something like: switch (strtolower(substr($input, -1))) { case 'k': $input*=1000; break; // similarly for m, M, b, B. } Assuming your data is well

笔记

落爺英雄遲暮 提交于 2019-11-29 19:36:26
ECMAScript 为数组定义了五个迭代方法。 每个方法都接收两个参数:要在每一项上运行的函数和(可选的)运行该函数的作用域对象——影响this的值。 传入这些方法中的函数会接收三个参数:数组项的值、该项在数组中的位置和数组对象本省。 根据使用的方法不同,这个函数执行后的返回值可能会也可能不会影响方法的返回值。 以下是这五个迭代方法的作用。 1、every(); 对数组中的每一项运行给定函数,如果该函数对每一项都返回true,则返回true。 2、some(); 对数组的每一项运行给定函数,如果该函数对任一项返回true,则返回true。 var numbers = [1, 2, 3, 4, 5, 4, 3, 2, 1]; var everyResult = numbers.every(function(item, index, array){ return (item > 3); }) console.log(everyResult); //false var someResult = numbers.some(function(item, index, array) { return (item > 3); }) console.log(someResult); //true 3、filter(); 对数组中的每一项运行给定函数,返回改函数会返回true的项组成的数组。

JSON.parse parses / converts big numbers incorrectly

血红的双手。 提交于 2019-11-29 18:45:47
问题 My problem is really simple but I'm not sure if there's a "native" solution using JSON.parse. I receive this string from an API : { "key" : -922271061845347495 } When I'm using JSON.parse on this string, it turns into this object : { "key" : -922271061845347500 } As you can see, the parsing stops when the number is too long (you can check this behavior here). It has only 15 exact digits, the last one is rounded and those after are set to 0. Is there a "native" solution to keep the exact value

Fixed point vs Floating point number

。_饼干妹妹 提交于 2019-11-29 18:40:54
I just can't understand fixed point and floating point numbers due to hard to read definitions about them all over Google. But none that I have read provide a simple enough explanation of what they really are. Can I get a plain definition with example? Gabe A fixed point number has a specific number of bits (or digits) reserved for the integer part (the part to the left of the decimal point) and a specific number of bits reserved for the fractional part (the part to the right of the decimal point). No matter how large or small your number is, it will always use the same number of bits for each