numbers

Java always give me wrong result with huge numbers [duplicate]

柔情痞子 提交于 2019-12-08 11:42:47
问题 This question already has answers here : Wrong result by Java Math.pow (6 answers) Closed 2 years ago . I wrote this line of code: System.out.println(Math.pow(7, 23) % 143); // 7^23 mod 143 I expected the output to be 2 but the output was 93.0 . Does someone know what I'm doing wrong? 回答1: The number "overflows" double , which is what Math.pow() expects and returns. Use a BigInteger instead: BigInteger.valueOf(7) .pow(23) .mod(BigInteger.valueOf(143)) Or in a single step, as suggested by

How to grab HTML snippet via Applescript with Javascript

二次信任 提交于 2019-12-08 11:27:50
问题 Here is my situation in detail. I have figured out how to login to a website, not using javascript, but using "keystrokes", "tabs" and "returns" to find the username and password fields. I know this can be unreliable as websites change but for now I am just trying to keep it simple. After I log in to a site, like a bank account, I want to grab the account balance and import it to Numbers. I have figured out how to insert a predermined text into a specific cell in Numbers and probably could

VB.Net Extract numbers from string function

蹲街弑〆低调 提交于 2019-12-08 10:39:48
问题 My request is one that can extract a number somewhat by a search. Example: animalsOwned|4 would return an containing "4" animals|3|2|1|3 would return an array containing "3", "2", "1", "3" This would make it easier for me during a file stream reader. Thank you 回答1: Try regular expression. It's a powerful tool for simple text parsing. Imports System.Text.RegularExpressions Namespace Demo Class Program Shared Function Main(ByVal args As String()) As Integer Dim array As Integer() =

Telephone Word Generator Implementation in Swift based on C# Program

给你一囗甜甜゛ 提交于 2019-12-08 10:08:34
问题 I'm currently trying to implement the Telephone word generator. I looked all around the web for something that I could use and this is what I found. I found this implementation in C#: public static void printPhoneWords(int[] number) { char[] output = new char[number.length]; printWordsUtil(number,0,output); } static String[] phoneKeys= new String[]{"0", "1", "ABC", "DEF", "GHI", "JKL", "MNO", "PQRS", "TUV", "WXYZ"}; private static void printWordsUtil(int[] number, int curDigIndex, char[]

regex to allow decimals, but no commas

落爺英雄遲暮 提交于 2019-12-08 10:02:29
问题 I need a regex expression that allows decimals but no commas. Such as: 1200.00 or 50.00 or 40 or 1 The expression is used in a validation to make sure people put in a price as a number, but no commas. I currently have a regex that allows for commas, numbers, and decimals, but I cannot seem to get the commas out. This is the current regex that I have which doesnt allow commas or decimals, but I want decimals in there /^[0-9\ ]+$/, Thanks for your help. 回答1: Something like this should work: ^\d

Get factors of a number

╄→尐↘猪︶ㄣ 提交于 2019-12-08 08:32:22
问题 I need to get two factors ( x, y ) of a given number ( n ) such that: x * y <= n x * y should be as close to n as possible x and y should be as close to each other as possible. Examples: n = 16 => x = 4, y = 4 n = 17 => x = 4, y = 4 n = 18 => x = 6, y = 3 n = 20 => x = 5, y = 4 Any language will do but preferably php. EDIT -- CLARIFICATION I want to create a rectangle, x units wide * y units tall such that its area is as close to n as possible. x and y must be integers. If n is a prime number

Why is a number having greater than 15 digits auto rounded in javascript? [duplicate]

冷暖自知 提交于 2019-12-08 07:35:48
问题 This question already has answers here : Large numbers erroneously rounded in JavaScript (6 answers) Closed 6 years ago . I have a problem with javascript number. My problem is that I have a currency field in HTML and when I use javascript to calculate with another field; then if this input field has the number of digits > 15 then this is auto rounded. You can try this in firebug. E.g: (9999999999999999); 10000000000000000 How do I fix this? 回答1: the following link may help you Large numbers

How would I find the answer to X% of X in PHP?

久未见 提交于 2019-12-08 07:26:31
问题 I have two variables: $percent = '3.5'; //this is the percentage $order = 400; //so how would i get $percent of $order? Now in PHP how would I find out what 3.5% of 400 is (I know its 14) - but would like to know how to calculate it directly in PHP using those two variables above. Appreciate your response. 回答1: "Percent" just means "per 100" or "over 100" or "/ 100" $percentOfOrder = $order * ($percent / 100); 回答2: You could make a percentOf function: function percentOf($number, $percent){

how do i print currency format in javascript

笑着哭i 提交于 2019-12-08 06:45:26
问题 i have some price values to display in my page. i am writing a function which takes the float price and returns the formatted currency val with currency code too.. like fnPrice(1001.01) should print $ 1,000.01 回答1: You've got to do this by hand, there is nothing builtin into JS. For an example look at this post here: How can I format numbers as money in JavaScript? 回答2: You can using code : function formatMoney(number) { return number.toLocaleString('en-US', { style: 'currency', currency:

Why isn't this int incrementing?

我的梦境 提交于 2019-12-08 06:45:10
问题 I am stuck on probably an easy problem, but I really can't find why it isn't working. I am trying to increase mijnScore with 1 each time the method gets called. But somehow mijnScore goes back to 0 after the method is done. int mijnScore = 0; ... public void updateUI() { System.out.println("updateUI"); SwingUtilities.invokeLater(new Runnable() { public void run() { ikWin = true; while(ikWin) { mijnScore++; System.out.println("mijnScore" + mijnScore); Scoresp1.setText(mijnScore + ""); ikWin =