decimal

Using a dynamic precision value in number_to_currency based on the decimal value

喜欢而已 提交于 2019-12-11 06:22:56
问题 Thoughout our app we use number_to_currency(value, :precision => 2) . However, we now have a requirement whereby the value may need displaying to three or more decimal places, e.g. 0.01 => "0.01" 10 => "10.00" 0.005 => "0.005" In our current implementation, the third example renders as: 0.005 => "0.01" What's the best approach for me to take here? Can number_to_currency be made to work for me? If not, how do I determine how many decimal places a given floating point value should be displayed

Converting Decimal to Hexadecimal and Octal

自作多情 提交于 2019-12-11 06:16:32
问题 Show how to write a constant in C, whose decimal value is 65 as a. a hexadecimal constant 65/16 = 1 r1 1/16 = 0 r1 Hexadecimal constant = 11 b. an octal constant (in C) 65/8 = 8 r1 8/8 = 1 r0 1/8 = 0 r1 Octal constant = 101 Is this the right way to convert constants in C? 回答1: You just need a while loop and a string. As this is homework, I do not think I should say more than that. 回答2: The method is to divide by the base until the result is less than the base. So 65/8 gives 8 r1 but you don't

Weka decimal precision

匆匆过客 提交于 2019-12-11 05:57:52
问题 After getting very excited by what seemed like excellent results from using the MLP within the Weka GUI on my pricing data, I've coded up a bit of Java that uses an MLP with the same parameters. Here is where the fun starts, the results are completely different, I've now found that this appears to be be due to rounding differences. The GUI rounds to 3 dp, my java code rounds to 5 dp. I've looked through the manuals but I can't seem to find an option to force the GUI to use 5dp precision on

Having difficulties converting a string into decimal

偶尔善良 提交于 2019-12-11 05:57:27
问题 Thanks for taking the time to assist me with my problem. In the code I'm writing, I'm iterating through a table, I get the appropriate values (confirmed it using the debugger) and I'm parsing them to the appropriate types before and finally I add them to an Object to be serialized into XML. However, I bumped into a problem and that is I can't seem to find a way to parse the string into a decimal value. Take a look: if (DateTime.TryParse(dateString, culture, styles, out date)) { decimal

Why is that I get zeroes added to decimal values that I am pulling from MS Access database?

混江龙づ霸主 提交于 2019-12-11 05:15:55
问题 I originally asked this here, but had to ask separately. Why is it that I'm getting values like 2.01000000 from the database, even though I am storing only decimal 2.01? In my database I see it as 2.01 and not 2.010000. The field in MS Access is of type decimal, and I store it as 2.01 itself. I am pulling the value like this: while(reader.Read()) Convert.ToDecimal(reader[i]); I get the value as 2.010000000. Why? Is there a better approach to read decimal values from database? I have set the

Converting a string of numbers to hex and back to dec pandas python

旧城冷巷雨未停 提交于 2019-12-11 04:53:08
问题 I currently have a string of values which I retrieved after filtering through data from a csv file. ultimately I had to do some filtering of the data but I have the same numbers as a list, dataframe, or array. I just need to take the numbers in the string and convert them to hex and then take the first 8 numbers of the hex and convert that to dec for each element in the string. Lastly I also need to convert the last 8 of the same hex and then to dec as well for each value in the string. I

Java converting negative binary back to integer

允我心安 提交于 2019-12-11 04:44:19
问题 I'm trying to convert an base 10 number to a base 2 and back to base 10. It works only for positive argument_decimal argument_binary = Integer.toBinaryString(argument_decimal); back_converted_argument_decimal = Integer.valueOf(argument_binary, 2); For argument_decimal beeing negative, I get "java.lang.NumberFormatException: For input string: "11111111111111111111111111111111"" EDIT: here is what I do: latitude_binary = Integer.toBinaryString((int)(latitude_decimal * 1000000)); back_converted

python function to set accuracy of float

≡放荡痞女 提交于 2019-12-11 04:07:23
问题 I would like to make a function: def accuracy(number, index): For example accuracy(2.5e-10, -5) would return 0. accuracy(49, 2) would return 0. accuracy(50, 2) would return 100. So basically it would round to the closest 10 power of the index index How would you do that? 回答1: def accuracy(n, i): return round(float(n) / 10**i) * 10**i 来源: https://stackoverflow.com/questions/18219400/python-function-to-set-accuracy-of-float

Pandas data frame. Change float format. Keep type “float”

我的未来我决定 提交于 2019-12-11 04:04:16
问题 I'm trying to change a format of pd data frame column without changing the type of data. Here is what I have: df = pd.DataFrame({'Age': [24.0, 32.0}]) I'd like to represent Age in 24 32 type or 24.00 32.00 and keep them as floats. Here is what I can do: df['Age'].map('{:,.2f}'.format) But this line changes the type of data to object. I was also trying to apply: ` df = df.style.format({'Age': '{:,.2f}'.format})` but there is something wrong in it. Please help to figure out the right way. 回答1:

Binary to Decimal Conversion using Divide-and-conquer

眉间皱痕 提交于 2019-12-11 04:04:07
问题 I am currently stuck on an assignment and have looked nearly everywhere for even a hint at what I am trying to do. The assignment is simple, we are to be given a binary number in the form of a vector (e.g. [1,1,1,1] and we are to compute the decimal form of this number and put in back into the same vector form (e.g. [1,5] for the answer to the previous example). While at first I thought this would have an easy solution, I soon found that we are to use this method to calculate extremely large