decimal

PHP change the decimal separator

主宰稳场 提交于 2021-01-02 20:08:50
问题 In some circumstances PHP is changing the decimal separator after the operation, here is an example: <?php echo $amount; //21.960000 echo $this->obj_vat->vat; //10.00 $amount= $amount + ( $amount * ( $this->obj_vat->vat / 100 ) ); echo $amount; //24,156 ?> Why the decimal separator changes to ','? This is a multilanguage website. In the spanish version the locale is set to spanish (es_ES), and the decimal separator is ','. That's why is changing. A solution is to force the LC_NUMERIC to

PHP change the decimal separator

不打扰是莪最后的温柔 提交于 2021-01-02 20:04:01
问题 In some circumstances PHP is changing the decimal separator after the operation, here is an example: <?php echo $amount; //21.960000 echo $this->obj_vat->vat; //10.00 $amount= $amount + ( $amount * ( $this->obj_vat->vat / 100 ) ); echo $amount; //24,156 ?> Why the decimal separator changes to ','? This is a multilanguage website. In the spanish version the locale is set to spanish (es_ES), and the decimal separator is ','. That's why is changing. A solution is to force the LC_NUMERIC to

In jq, how to get tonumber to output decimal instead of scientific notation

青春壹個敷衍的年華 提交于 2020-12-31 10:55:05
问题 In a JSON object, given the string "0.0000086900" as the value of a key-value pair, if I do |tonumber on this, 8.69e-06 gets returned. How can I ensure that only decimals are ever returned? In the case above, this would be 0.0000086900 SOLUTION (based on Peak's code snippet below) def to_decimal: def rpad(n): if (n > length) then . + ((n - length) * "0") else . end; def lpad(n): if (n > length) then ((n - length) * "0") + . else . end; tostring | . as $s | [match( "(?<sgn>[+-]?)(?<left>[0-9]*

In jq, how to get tonumber to output decimal instead of scientific notation

你说的曾经没有我的故事 提交于 2020-12-31 10:54:46
问题 In a JSON object, given the string "0.0000086900" as the value of a key-value pair, if I do |tonumber on this, 8.69e-06 gets returned. How can I ensure that only decimals are ever returned? In the case above, this would be 0.0000086900 SOLUTION (based on Peak's code snippet below) def to_decimal: def rpad(n): if (n > length) then . + ((n - length) * "0") else . end; def lpad(n): if (n > length) then ((n - length) * "0") + . else . end; tostring | . as $s | [match( "(?<sgn>[+-]?)(?<left>[0-9]*

In jq, how to get tonumber to output decimal instead of scientific notation

和自甴很熟 提交于 2020-12-31 10:54:27
问题 In a JSON object, given the string "0.0000086900" as the value of a key-value pair, if I do |tonumber on this, 8.69e-06 gets returned. How can I ensure that only decimals are ever returned? In the case above, this would be 0.0000086900 SOLUTION (based on Peak's code snippet below) def to_decimal: def rpad(n): if (n > length) then . + ((n - length) * "0") else . end; def lpad(n): if (n > length) then ((n - length) * "0") + . else . end; tostring | . as $s | [match( "(?<sgn>[+-]?)(?<left>[0-9]*

How can I locale-format a python Decimal and preserve its precision?

耗尽温柔 提交于 2020-12-29 05:22:25
问题 How can I format a Decimal using a locale? To describe by examples, I'm trying to define a function f such that in the US English locale: f(Decimal('5000.00')) == '5,000.00' f(Decimal('1234567.000000')) == '1,234,567.000000' Some things that don't work: f = str doesn't use locale; f(Decimal('5000.00')) == '5000.00' f = lambda d: locale.format('%f', d) doesn't preserve the decimal precision; f(Decimal('5000.00')) == '5000.000000' f = lambda d: locale.format('%.2f', d) uses a fixed precision,

Limiting the number of decimals in a dataframe (R)

放肆的年华 提交于 2020-12-28 14:56:27
问题 I would like to limit the number of decimals when a data frame is imported. My .txt input have 16 decimals to each row in collumn "Value". My dataframe look like that: Value 0.202021561664556 0.202021561664556 0.202021561664556 0.202021561664556 ... My expected dataframe Value 0.20202156 0.20202156 0.20202156 0.20202156 ... Real input (DF) that not works: DF <- "NE001358.Log.R.Ratio -0.0970369274475688 0.131893549586039 0.0629266495860389 0.299559132381831 -0.0128804337656807 0

Cannot import Decimal module

吃可爱长大的小学妹 提交于 2020-12-27 06:37:40
问题 I am trying to do some simple decimal math to practice with the Tkinter GUI, but for some reason I cannot import Decimal: >>> from decimal import Decimal Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/decimal.py", line 139, in <module> import math as _math File "math.py", line 3, in <module> from decimal import Decimal ImportError: cannot import name Decimal I am using Python 2.7.11 This is making me

Cannot import Decimal module

こ雲淡風輕ζ 提交于 2020-12-27 06:37:25
问题 I am trying to do some simple decimal math to practice with the Tkinter GUI, but for some reason I cannot import Decimal: >>> from decimal import Decimal Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/decimal.py", line 139, in <module> import math as _math File "math.py", line 3, in <module> from decimal import Decimal ImportError: cannot import name Decimal I am using Python 2.7.11 This is making me

Use more decimals in Python

烈酒焚心 提交于 2020-12-26 07:26:26
问题 I already have a code which uses the bisection method to determine the value of something, the problem is that I need a value so precise, more than 15 decimals, and at some point python stops getting smaller digits I am aware of the Decimals library but do I really have to rewrite every parameter in the code as Decimals(parameter) ? because I have lots of parameters is there a way to convert every float in the code to Decimals universally? or is there a way to solve this problem all together