decimal

Decimal Value is Zero when it should be 0.0x

元气小坏坏 提交于 2019-12-13 02:08:06
问题 If this was previously talked about, I'm sorry, I had a hard time searching on this. I am calculating a depreciation rate. One portion of our calculation is 1/life in months. My table stores this data in a decimal field. I tried test = 1 / estimatedLife; but the result of the calculation of test (which is defined as a decimal ) is 0. Say the estimated life is 36 months. So 1/36 should equal 0.02777778. Any thoughts of what I am doing wrong? BTW, I changed the test to a double and had the same

Convert decimal (SQL) to double C++

南笙酒味 提交于 2019-12-13 00:19:02
问题 I have a SQL query which return records with only one column of type decimal (18,18). In the C++ code I need to convert each value to double to add it to an array. What's the best way of doing it? Thank you 回答1: I would suggest converting it to a Real before taking it from the database they are roughly the same datatype. http://msdn.microsoft.com/en-us/library/ms173773.aspx 来源: https://stackoverflow.com/questions/6746010/convert-decimal-sql-to-double-c

How to convert a string to an int or decimal?

瘦欲@ 提交于 2019-12-12 22:13:44
问题 I have this code: Console.WriteLine("What is the price of the product?"); Decimal price = Decimal.Parse(Console.ReadLine()); I take a input as a string as either a int or/and decimal number and convert it to a variable. Or well, that is my intention. The input is a price of a product and it can have decimals or it cannot. I you only type in ints, it works, but with decimals it crashes. I'm new to this and I can't seem to find an answer. 回答1: Use TryParse to prevent exception: while (true) {

Converting exponential number to decimal 1.11111117E+9 - trailing digits become zero

我只是一个虾纸丫 提交于 2019-12-12 21:20:23
问题 I'm trying to convert and exponential number 1.11111117E+9 which is actually a 10 digit number '1111111111'. When I'm trying to convert this exponential number using decimal.TryParse method it is making last 3 digits as zero and giving the number as ' 111111000 '. This is happening with any 10 digit number. decimal amount; decimal.TryParse("1.11111117E+9", NumberStyles.Any, null, out amount); This is weird but I'm not able to figure out what's the issue here, can anybody tell me what's wrong

decimal separator oracle

纵然是瞬间 提交于 2019-12-12 21:16:30
问题 I need to replace comma with point and then i need my value to be a number. So i wrote this: select replace('12345,6789', ',' , '.') from dual --it works fine but then I want to convert to_number that value and I get the error: "invalid number" 回答1: The to_number() function uses the session's NLS_NUMERIC_CHARACTERS setting to decide how to interpret commas and periods. If you know your string will always have a comma as decimal separator you can override that as part of the call, using the

How to create a decimal.Decimal object with a given number of significant figures?

浪尽此生 提交于 2019-12-12 20:23:05
问题 The best way I've found to produce a decimal.Decimal number with a specific number of significant figures is the one used to initialize the variable kluge below: import decimal THIS_IS_JUST_AN_EXAMPLE = 0.00001/3.0 with decimal.localcontext() as c: c.prec = 5 kluge = decimal.Decimal(THIS_IS_JUST_AN_EXAMPLE) + decimal.Decimal(0) naive = decimal.Decimal(THIS_IS_JUST_AN_EXAMPLE) print repr(kluge) print repr(naive) # Decimal('0.0000033333') # Decimal('0

Change number of decimals in Woocommerce cart totals

喜你入骨 提交于 2019-12-12 20:18:26
问题 In Woocommerce, I've set the number of decimal to 7 on in Woocommerce general settings, so I can display the product price like this $0.0453321 . I'm wondering if I can set/round the cart total to only 2 decimals (something like this $2.34 )? 回答1: The correct way is to change just the number of allowed decimals for cart and checkout pages only: add_filter( 'wc_get_price_decimals', 'change_prices_decimals', 20, 1 ); function change_prices_decimals( $decimals ){ if( is_cart() || is_checkout() )

Convert Integer to Generic Base Matlab

笑着哭i 提交于 2019-12-12 18:33:51
问题 I'm trying to convert a base-10 integer k into a base-q integer, but not in the standard way. Firstly, I'd like my result to be a vectors (or a string 'a,b,c,...' so that it can be converted to a vector, but not 'abc...'). Most importantly, I'd like each 'digit' to be in base-10. As an example, suppose I have the number 23 (in base-10) and I want to convert it to base-12. This would be 1B in the standard 1,...,9,A,B notation; however, I want it to come out as [1, 11]. I'm only interested in

Why is the data stored in a Float datatype considered to be an approximate value?

风格不统一 提交于 2019-12-12 18:09:35
问题 I've never understood why a float datatype is considered an approximation while a decimal datatype is considered exact. I'm looking for a good explanation, thanks. 回答1: well, you're right - it's misleading to make such a blanket statement. to understand completely you need to grasp two things. first, decimal is intended for storing (exactly) decimal values with a fixed number of decimal places. typically, money (where the decimals are cents, for example). that's a very specific use case. it's

Change number of decimals on Woocommerce displayed cart subtotal

。_饼干妹妹 提交于 2019-12-12 17:20:11
问题 I am Using "Change number of decimals in Woocommerce cart totals" answer code to display the total with 2 decimals . The code works fine for the displayed total in cart and checkout pages. I would like if possible to do the same thing for the subtotal too. Any help is appreciated. 回答1: To format the displayed subtotal amount with 2 decimals in cart and checkout pages use the following: // Displayed formatted cart subtotal in cart and checkout pages add_filter( 'woocommerce_cart_subtotal',