numbers

PHP Get Experience by Level

ぃ、小莉子 提交于 2019-12-11 09:42:11
问题 I have this piece of code that loops 1 through 99 and is a formula. function getExperienceByLevel ($maxLevel) { $levels = array (); $current = 0; for ($i = 1; $i <= $maxLevel; $i++) { $levels[$i - 1] = floor ($current / 4); $current += floor($i+300*pow(2, ($i/9.75))); } return $levels; } First you initiate it like so $aLevels = getExperienceByLevel(99); then to see how much EXP you need to get to level 6 you do this echo $aLevels[5]; since it's an array. Now I'm trying to do reverse. Get

How to localize numerals?

偶尔善良 提交于 2019-12-11 09:25:18
问题 Ok, I'm using mathematical equations to output numbers, though, I need this to be compatible for all languages. Currently, all language strings are within a php array called $txt , and each key of the array gets called for that language. I'm outputting the following: Column 1 , Column 2 , Column 3 , and so on, as well as Row 1 , Row 2 , Row 3 , and so on. The calculations are done via php and javascript, so I'm wondering on the best approach for how to support all languages for the numbers

Get number of replacements [duplicate]

微笑、不失礼 提交于 2019-12-11 09:14:58
问题 This question already has answers here : How would you count occurrences of a string (actually a char) within a string? (30 answers) Closed 5 years ago . Is there a method to get the number of replacements using .Replace("a", "A"); ? Example: String string_1 = "a a a"; String string_2 = string_1.Replace("a", "A"); In this case, the output should be 3, because a was replaced with A 3 times. 回答1: You can get the count using .Split function : string_1.Split(new string[] { "a" },

Decimal money format

依然范特西╮ 提交于 2019-12-11 08:49:14
问题 how to convert all numbers to xx,xx decimal format without exploding number or string? like; 8,9 --> 8,90 8,99 --> 8,99 12,1 --> 12,10 129,9 --> 129,90 any idea? 回答1: You can use number_format like: $n = 2.1; echo number_format($n, 2, ','); // 2,10 If you have commas as decimal separators in your input you can convert values to float with: $number = floatval(str_replace(',', '.', str_replace('.', '', $string_number))); str_replace('.', '', $string_number) is used to remove thousand separators

Calculate the nth Catalan number

僤鯓⒐⒋嵵緔 提交于 2019-12-11 08:39:46
问题 I wrote some code to calculate the Nth catalan number. However, it isn't returning the correct result when N=20 and onwards. The results when N<20 is correct though, so I'm not sure what is wrong. So, when N=20, its supposed to return 6564120420, but it returns 2269153124 for me. Can someone point me in the right direction? #include <iostream> using namespace std; unsigned long int countTree(unsigned int N) { //used to store catalan numbers unsigned long int catalan[N+1]; //N(0)=N(1)=1

Java Number Palindrom

瘦欲@ 提交于 2019-12-11 08:31:53
问题 I want to write a palindrome program which will print all palindrome numbers created by multiplying two-digit numbers (10-99)? Here is my code so far: public class PrintPalindrom { public int printPalindrom (int a, int b) { int result = a*b; int reverse = 0; if (a >= 10 && a <= 99 && b >= 10 && b <= 99) { while (result != 0) { reverse = reverse * 10; reverse = reverse + result % 10; result = result/10; System.out.println("palindrom is " + result); } } else { System.out.println("Wrong numbers"

JavaScript; How to set dot after three digits?

一曲冷凌霜 提交于 2019-12-11 08:18:16
问题 I have the following JavaScript code: var calculation = $('select[name=somevalue1] option:selected').data('calc')-($('select[name=somevalue1] option:selected').data('calc')/100*$('select[name=somevalue2] option:selected').data('calc'))-($('select[name=somevalue1] option:selected').data('calc')-($('select[name=somevalue1] option:selected').data('calc')/100*$('select[name=somevalue2] option:selected').data('calc')))/100*$('select[name=somevalue3] option:selected').data('calc'); $('#calculation'

Java Generic Type Number

混江龙づ霸主 提交于 2019-12-11 07:59:45
问题 I have read several pages on generic methods and have some sort of grasp on them, but I still don't understand them. So say I have a method to multiply two numbers and return the product: public double multiply(SomeNumberVariableType x, SomeNumberVariableType y){ return x * y; } How can I use bounded generics to have only a number type permitted as parameters? 回答1: Maybe this is your intention: public static <N extends Number> double multiply(N x, N y){ return x.doubleValue() * y.doubleValue(

Excel Print number with correct decimal Seperator

喜欢而已 提交于 2019-12-11 07:49:51
问题 I use the print function to export a Cell Value to csv file. I use this macro on several PCs with different Localization Settings. The problem i am experiencing is, that on some PCs the Output is 4,11 and 4.11 on others. Is there any Format Method, that allows me always write a Number with a semicolon as decimal Seperator? 回答1: As far as I'm aware, there is no format method for changing the decimal separator. Instead your options are temporarily telling Excel to use a special character or

Format numbers in JavaScript similar to C#

半城伤御伤魂 提交于 2019-12-11 07:42:23
问题 Is there a simple way to format numbers in JavaScript, similar to the formatting methods available in C# (or VB.NET) via ToString("format_provider") or String.Format() ? 回答1: You should probably have a look at the JQuery NUMBERFORMATTER plugin: Jquery Number Formatter And this question: Javascript easier way to format numbers 回答2: Generally Formatting numbers in JavaScript Formatting numbers for currency display and more. In jQuery autoNumeric (a decent number formatter & input helper with