decimal

C++ cout decimal alignment

a 夏天 提交于 2020-08-27 15:35:07
问题 I'm having a hard time aligning decimal values. I am pretty sure its a combination of right alignment and setprecision/fixed but it doesn't seem to be working. I know other questions have been asked on the topic but I haven't found a clear solution to getting a bunch of columns (unique cout statements to align). This is a chunk of my code: double total_collect, sales, country_tax, state_tax, total_tax; const double STATE_TAX_RATE = 0.04, COUNTRY_TAX_RATE = 0.02; // Compute taxes total_collect

C# Decimal.Epsilon

谁说胖子不能爱 提交于 2020-07-18 03:27:47
问题 Why doesn't Decimal data type have Epsilon field? From the manual, the range of decimal values is ±1.0 × 10e−28 to ±7.9 × 10e28. The description of Double.Epsilon: Represents the smallest positive Double value greater than zero So it seems, Decimal has such a (non-trivial) value too. But why isn't it easily accessible? I do understand that +1.0 × 10e−28 is exactly the smallest positive Decimal value greater than zero: decimal Decimal_Epsilon = new decimal(1, 0, 0, false, 28); //1e-28m; By the

number_format() php remove trailing zeros

一笑奈何 提交于 2020-07-06 20:59:32
问题 Is there a way with number_format() to leave out decimal places if the number is not a float/decimal? For example, I would like the following input/output combos: 50.8 => 50.8 50.23 => 50.23 50.0 => 50 50.00 => 50 50 => 50 Is there a way to do this with just a standard number_format() ? 回答1: You can add 0 to the formatted string. It will remove trailing zeros. echo number_format(3.0, 1, ".", "") + 0; // 3 A Better Solution: The above solution fails to work for specific locales. So in that

number_format() php remove trailing zeros

て烟熏妆下的殇ゞ 提交于 2020-07-06 20:58:20
问题 Is there a way with number_format() to leave out decimal places if the number is not a float/decimal? For example, I would like the following input/output combos: 50.8 => 50.8 50.23 => 50.23 50.0 => 50 50.00 => 50 50 => 50 Is there a way to do this with just a standard number_format() ? 回答1: You can add 0 to the formatted string. It will remove trailing zeros. echo number_format(3.0, 1, ".", "") + 0; // 3 A Better Solution: The above solution fails to work for specific locales. So in that

pandas.read_html not support decimal comma

☆樱花仙子☆ 提交于 2020-07-06 09:41:18
问题 I was reading an xlm file using pandas.read_html and works almost perfect, the problem is that the file has commas as decimal separators instead of dots (the default in read_html ). I could easily replace the commas by dots in one file, but i have almost 200 files with that configuration. with pandas.read_csv you can define the decimal separator, but i don't know why in pandas.read_html you can only define the thousand separator. any guidance in this matter?, there is another way to automate

How do I get a Decimal square root of a negative Decimal number in Python?

痴心易碎 提交于 2020-07-03 08:24:26
问题 To get the sqaure root of a negative number we could use cmath.sqrt. But either the real part or the imag part of the result is still a float: type (cmath.sqrt (Decimal (-8)).imag) result: float How do I get a Decimal square root of a negative Decimal number? For a positive number we could use: Decimal (8).sqrt () The result is still a Decimal. But it doesn't work on negative numbers: Decimal (-8).sqrt () {InvalidOperation}[] 回答1: You could implement a ComplexDecimal() class with that

NSDecimalNumber(x).intValue returns -2, 0, 15 and 199, depending on the amount of decimals in x (x = 199.999…5)

谁都会走 提交于 2020-06-26 04:26:06
问题 We found an interesting case in our business logic that totally breaks our logic and we don't understand why NSDecimalNumber and Decimal behaves the way it does. My playground for the cases is as follows: import Foundation let pQuantity = Decimal(string: "0.2857142857142857")! let pPrice = Decimal(string: "7.00000000000000035")! let calced = NSDecimalNumber(decimal: pQuantity * pPrice * Decimal(integerLiteral: 100)) // 200 let decimal = calced.decimalValue // 199

SQL Server: Convert varchar to decimal (with considering exponential notation as well)

爷,独闯天下 提交于 2020-06-25 17:27:23
问题 I need to convert data of a table and do some manipulation. One of the column datatypes is Varchar , but it stores decimal numbers. I am struggling to convert the varchar into decimal . I have tried CAST( @TempPercent1 AS DECIMAL(28, 16)) Problem is that data also has some values in exponential notation, for example: 1.61022e-016 . The sql query is throwing error on encountering such value. The error is Error converting data type varchar to numeric. How should I handle exponential notation