decimal

Converting String of binary digits to decimal number… using recursion

自闭症网瘾萝莉.ら 提交于 2020-01-13 18:00:53
问题 Comp sci professor gave us this problem in our homework... I'm not sure how to proceed and the code I have written seems to be failing miserably. Here is the prompt: (binary to decimal) Write a recursive method that parses a binary number as a string into a decimal integer. The method header is: public static String bin2Dec(String binaryString) write a test program that prompts the user to enter a binary string and displays its decimal equivalent. Any help greatly appreciated. Here is my code

Converting String of binary digits to decimal number… using recursion

淺唱寂寞╮ 提交于 2020-01-13 18:00:04
问题 Comp sci professor gave us this problem in our homework... I'm not sure how to proceed and the code I have written seems to be failing miserably. Here is the prompt: (binary to decimal) Write a recursive method that parses a binary number as a string into a decimal integer. The method header is: public static String bin2Dec(String binaryString) write a test program that prompts the user to enter a binary string and displays its decimal equivalent. Any help greatly appreciated. Here is my code

Converting String of binary digits to decimal number… using recursion

南笙酒味 提交于 2020-01-13 18:00:03
问题 Comp sci professor gave us this problem in our homework... I'm not sure how to proceed and the code I have written seems to be failing miserably. Here is the prompt: (binary to decimal) Write a recursive method that parses a binary number as a string into a decimal integer. The method header is: public static String bin2Dec(String binaryString) write a test program that prompts the user to enter a binary string and displays its decimal equivalent. Any help greatly appreciated. Here is my code

How can I strip zeros and decimal points off of decimal strings?

故事扮演 提交于 2020-01-13 03:57:13
问题 The following code currently outputs: 12.1 12.100 12.1000 12.00 12 12.0000 How can I change it so it outputs: 12.1 12.1 12.1 12 12 12 Math.Round seems to be the thing, but it makes me define how many decimal places I want, but I want them to be variable as above. If there is no mathematical way to do it, I'll just strip the zeros and decimal points off the right side of the strings, but would think there is a math way to handle this. using System; using System.Collections.Generic; namespace

.NET decimal cross-platform standard

好久不见. 提交于 2020-01-11 12:22:22
问题 If I save C# decimal array to a binary blob with a binary writer, will I be able to seamlessly read this blob in Java or Python or R? Do these language have a corresponding data type or is there a cross-platform standard that .NET decimal adheres to? I am converting all my numeric data to decimals before storing, because when an array of decimals is diffed and then compressed, the resulting blob size is much smaller for real world data than a float blob compressed by any algo (my tests show c

.NET decimal cross-platform standard

試著忘記壹切 提交于 2020-01-11 12:22:05
问题 If I save C# decimal array to a binary blob with a binary writer, will I be able to seamlessly read this blob in Java or Python or R? Do these language have a corresponding data type or is there a cross-platform standard that .NET decimal adheres to? I am converting all my numeric data to decimals before storing, because when an array of decimals is diffed and then compressed, the resulting blob size is much smaller for real world data than a float blob compressed by any algo (my tests show c

Matching decimals in strings using matcher()

◇◆丶佛笑我妖孽 提交于 2020-01-11 11:51:29
问题 I have a question regarding the matcher. Currently I am trying to read a string and store all the digits into an array. My question is, how do you try to match both integers and decimals? I have an array of doubles called: double[] thisArray = new double[20]; Into this array, i am trying to store all the numbers I extract from the string. Matcher temp = Pattern.compile("(\d+)").matcher(x); That is my function for the matcher. But this only matches integers. I want to match both integers and

Why does Python show `0.2 + 0.1` as `0.30000000000000004`? [duplicate]

大憨熊 提交于 2020-01-11 11:27:11
问题 This question already has answers here : Can someone explain this: 0.2 + 0.1 = 0.30000000000000004? [duplicate] (2 answers) Closed 5 years ago . I have written the following code for generating a range with floats: def drange(start, stop, step): result = [] value = start while value <= stop: result.append(value) value += step return result When calling this function with this statement: print drange(0.1,1.0,0.1) I expected to obtain this: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0] But

Why does Python show `0.2 + 0.1` as `0.30000000000000004`? [duplicate]

纵然是瞬间 提交于 2020-01-11 11:27:08
问题 This question already has answers here : Can someone explain this: 0.2 + 0.1 = 0.30000000000000004? [duplicate] (2 answers) Closed 5 years ago . I have written the following code for generating a range with floats: def drange(start, stop, step): result = [] value = start while value <= stop: result.append(value) value += step return result When calling this function with this statement: print drange(0.1,1.0,0.1) I expected to obtain this: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0] But

Formatting an SQL numeric query result with an arbitrary number of decimal places

时光怂恿深爱的人放手 提交于 2020-01-11 06:42:12
问题 I have a database table with these two columns: Amount: numeric (18,0) DecimalPlaces: numeric (18,0) This table can store amounts in various currencies, with the decimal place removed from the amount (I can't change this data model). For example, there might be two rows like this: 1290, 2 (This is £12.90, needs to appear as "12.90") 3400, 0 (This is 3400 Japanese Yen, needs to appear as "3400") I need an SQL query for both Oracle and SQL Server that will format each amount with the correct