scientific-notation

exponent digits in scientific notation in Python

安稳与你 提交于 2021-02-16 18:26:07
问题 In Python, scientific notation always gives me 2 digits in exponent: print('%17.8E\n' % 0.0665745511651039) 6.65745512E-02 However, I badly want to have 3 digits like: 6.65745512E-002 Can we do this with a built-in configuration/function in Python? I know my question is basically the same question as: Python - number of digits in exponent, but this question was asked 4 years ago and I don't want to call such a function thousand times. I hope there should be a better solution now. 回答1:

Specify float_format differently for each column (scientific notation vs decimal precision)

依然范特西╮ 提交于 2021-02-05 09:34:07
问题 I have multiple columns, some I want in scientific notation, others to a specific level of decimal precision: Frequency n 0 0.0023 2.3 1 0.0420 4.5 2 0.5460 6.7 3 0.1230 8.9 Frequency can have small orders of magnitude, so I end up with a billion zeros. The 'n' column should have a set number of decimal places. I've attempted to do the following on the 'Frequency' column: fntables['Frequency'].options.display.float_format = '{:.2e}'.format This returns the expected error that "'Series' object

Scientific notation wrongly converts to numbers

↘锁芯ラ 提交于 2021-01-29 03:53:48
问题 I've got a table of data with scientific notation numbers such as 1.1e-07 . When I try to convert these numbers to normal numbers with as.numeric, R gives me wrong numbers, like: 1.1e-07: 5977 1.4e-06: 5633 etc. How can I fix this? Update: thanks, it really was about factors. 回答1: Your numbers are most probably defined as factors. This will result in as.numeric not returning the "value" of the input but the factor level sequence number. x <- as.factor(c(1.1e-7, 2e-8)) ## convert two numbers

Scientific notation wrongly converts to numbers

落花浮王杯 提交于 2021-01-29 03:50:54
问题 I've got a table of data with scientific notation numbers such as 1.1e-07 . When I try to convert these numbers to normal numbers with as.numeric, R gives me wrong numbers, like: 1.1e-07: 5977 1.4e-06: 5633 etc. How can I fix this? Update: thanks, it really was about factors. 回答1: Your numbers are most probably defined as factors. This will result in as.numeric not returning the "value" of the input but the factor level sequence number. x <- as.factor(c(1.1e-7, 2e-8)) ## convert two numbers

MongoDB converts number to string in scientific notation

半城伤御伤魂 提交于 2021-01-28 05:00:20
问题 I want to get full number as a String , but instead "1490650000000" it returns scientific notation "1.49065e+12" Here's how I try to convert it: {$substr: ["$myNumber", 0, -1]}; Any ideas how to prevent it? Note: I'm using v3.6 and can't upgrade to use $toString (thanks mlab). 回答1: If you have mongodb 4.0 then you can use $toLong aggregation db.collection.aggregate([ { "$project": { "myNumber": { "$toLong": "$myNumber" } } } ]) 回答2: You can try as below. db.collectionName.aggregate([ {

Does std::scientific always result in normalized scientific notation for floating-point numbers?

 ̄綄美尐妖づ 提交于 2021-01-27 07:06:46
问题 Scientific notation defines how numbers should be displayed using a sign, a number and an exponent but it does not state that the visualization is normalized. An example: -2.34e-2 (normalized scientific notation) is the same as -0.234e-1 (scientific notation) Can I rely on the following code always producing the normalized outcome? Edit: except NAN and INF as pointed out in the answers. template<typename T> static std::string toScientificNotation(T number, unsigned significantDigits) { if

Does std::scientific always result in normalized scientific notation for floating-point numbers?

柔情痞子 提交于 2021-01-27 07:06:39
问题 Scientific notation defines how numbers should be displayed using a sign, a number and an exponent but it does not state that the visualization is normalized. An example: -2.34e-2 (normalized scientific notation) is the same as -0.234e-1 (scientific notation) Can I rely on the following code always producing the normalized outcome? Edit: except NAN and INF as pointed out in the answers. template<typename T> static std::string toScientificNotation(T number, unsigned significantDigits) { if

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]*