Exponential to Float (Getting ALL decimal numbers of Float)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I need to get ALL decimal numbers possible, but I have a limit of 19 number char on the spinbox. Setting a static numbers on how many decimal places will be and setting a static number of decimals (setDecimals()) is not acceptable since the value I am getting is dynamic.
For example, I want to convert Hertz:
Hertz: 1.00
Megahertz: 1e-6
GigaHertz: 1e-9
I want it to be in this format:
1.00,
0.000006,
0.000000009,
Yes! Decimal places are dynamic.
This is the code for conversion (Value of dictionary is not yet finished):
conversion_formula = {'Hz': 1, 'kHz': 1e-3, 'MHz': 1e-6, 'GHz': 1e-9,
's': 1, 'ms': 1e-3, 'us': 1e-6, 'ns': 1e-9,
'V': 1, 'mV': 1e-3}
if FREQUENCY_UNIT_NAME == title or AMPLITUDE_UNIT_NAME == title:
output_value = input_value * (conversion_formula[current_unit] / conversion_formula[base_unit])
elif title == TIME_UNIT_NAME:
output_value = input_value * (conversion_formula[base_unit] / conversion_formula[current_unit])
python
|
show 2 more comments
I need to get ALL decimal numbers possible, but I have a limit of 19 number char on the spinbox. Setting a static numbers on how many decimal places will be and setting a static number of decimals (setDecimals()) is not acceptable since the value I am getting is dynamic.
For example, I want to convert Hertz:
Hertz: 1.00
Megahertz: 1e-6
GigaHertz: 1e-9
I want it to be in this format:
1.00,
0.000006,
0.000000009,
Yes! Decimal places are dynamic.
This is the code for conversion (Value of dictionary is not yet finished):
conversion_formula = {'Hz': 1, 'kHz': 1e-3, 'MHz': 1e-6, 'GHz': 1e-9,
's': 1, 'ms': 1e-3, 'us': 1e-6, 'ns': 1e-9,
'V': 1, 'mV': 1e-3}
if FREQUENCY_UNIT_NAME == title or AMPLITUDE_UNIT_NAME == title:
output_value = input_value * (conversion_formula[current_unit] / conversion_formula[base_unit])
elif title == TIME_UNIT_NAME:
output_value = input_value * (conversion_formula[base_unit] / conversion_formula[current_unit])
python
1e-9 and 0.000000009 are the same number, just written in a different way. Are you asking how toprint
in one format or the other?
– BlackBear
Jan 4 at 7:42
in 0.000000009 format. Because when I print the number, it's in 1e-9
– Arci Jeirico Malabanan
Jan 4 at 7:43
4
All decimal places? Really? What if the value is e.g. π, or even something simpler, like 1/3?
– zvone
Jan 4 at 7:44
I have a number char limit on the spinbox, up to 19.
– Arci Jeirico Malabanan
Jan 4 at 7:48
'%.19f' % x
formats float numbers to 19 digits
– BlackBear
Jan 4 at 7:51
|
show 2 more comments
I need to get ALL decimal numbers possible, but I have a limit of 19 number char on the spinbox. Setting a static numbers on how many decimal places will be and setting a static number of decimals (setDecimals()) is not acceptable since the value I am getting is dynamic.
For example, I want to convert Hertz:
Hertz: 1.00
Megahertz: 1e-6
GigaHertz: 1e-9
I want it to be in this format:
1.00,
0.000006,
0.000000009,
Yes! Decimal places are dynamic.
This is the code for conversion (Value of dictionary is not yet finished):
conversion_formula = {'Hz': 1, 'kHz': 1e-3, 'MHz': 1e-6, 'GHz': 1e-9,
's': 1, 'ms': 1e-3, 'us': 1e-6, 'ns': 1e-9,
'V': 1, 'mV': 1e-3}
if FREQUENCY_UNIT_NAME == title or AMPLITUDE_UNIT_NAME == title:
output_value = input_value * (conversion_formula[current_unit] / conversion_formula[base_unit])
elif title == TIME_UNIT_NAME:
output_value = input_value * (conversion_formula[base_unit] / conversion_formula[current_unit])
python
I need to get ALL decimal numbers possible, but I have a limit of 19 number char on the spinbox. Setting a static numbers on how many decimal places will be and setting a static number of decimals (setDecimals()) is not acceptable since the value I am getting is dynamic.
For example, I want to convert Hertz:
Hertz: 1.00
Megahertz: 1e-6
GigaHertz: 1e-9
I want it to be in this format:
1.00,
0.000006,
0.000000009,
Yes! Decimal places are dynamic.
This is the code for conversion (Value of dictionary is not yet finished):
conversion_formula = {'Hz': 1, 'kHz': 1e-3, 'MHz': 1e-6, 'GHz': 1e-9,
's': 1, 'ms': 1e-3, 'us': 1e-6, 'ns': 1e-9,
'V': 1, 'mV': 1e-3}
if FREQUENCY_UNIT_NAME == title or AMPLITUDE_UNIT_NAME == title:
output_value = input_value * (conversion_formula[current_unit] / conversion_formula[base_unit])
elif title == TIME_UNIT_NAME:
output_value = input_value * (conversion_formula[base_unit] / conversion_formula[current_unit])
python
python
edited Jan 4 at 7:49
Arci Jeirico Malabanan
asked Jan 4 at 7:41
Arci Jeirico MalabananArci Jeirico Malabanan
276
276
1e-9 and 0.000000009 are the same number, just written in a different way. Are you asking how toprint
in one format or the other?
– BlackBear
Jan 4 at 7:42
in 0.000000009 format. Because when I print the number, it's in 1e-9
– Arci Jeirico Malabanan
Jan 4 at 7:43
4
All decimal places? Really? What if the value is e.g. π, or even something simpler, like 1/3?
– zvone
Jan 4 at 7:44
I have a number char limit on the spinbox, up to 19.
– Arci Jeirico Malabanan
Jan 4 at 7:48
'%.19f' % x
formats float numbers to 19 digits
– BlackBear
Jan 4 at 7:51
|
show 2 more comments
1e-9 and 0.000000009 are the same number, just written in a different way. Are you asking how toprint
in one format or the other?
– BlackBear
Jan 4 at 7:42
in 0.000000009 format. Because when I print the number, it's in 1e-9
– Arci Jeirico Malabanan
Jan 4 at 7:43
4
All decimal places? Really? What if the value is e.g. π, or even something simpler, like 1/3?
– zvone
Jan 4 at 7:44
I have a number char limit on the spinbox, up to 19.
– Arci Jeirico Malabanan
Jan 4 at 7:48
'%.19f' % x
formats float numbers to 19 digits
– BlackBear
Jan 4 at 7:51
1e-9 and 0.000000009 are the same number, just written in a different way. Are you asking how to
print
in one format or the other?– BlackBear
Jan 4 at 7:42
1e-9 and 0.000000009 are the same number, just written in a different way. Are you asking how to
print
in one format or the other?– BlackBear
Jan 4 at 7:42
in 0.000000009 format. Because when I print the number, it's in 1e-9
– Arci Jeirico Malabanan
Jan 4 at 7:43
in 0.000000009 format. Because when I print the number, it's in 1e-9
– Arci Jeirico Malabanan
Jan 4 at 7:43
4
4
All decimal places? Really? What if the value is e.g. π, or even something simpler, like 1/3?
– zvone
Jan 4 at 7:44
All decimal places? Really? What if the value is e.g. π, or even something simpler, like 1/3?
– zvone
Jan 4 at 7:44
I have a number char limit on the spinbox, up to 19.
– Arci Jeirico Malabanan
Jan 4 at 7:48
I have a number char limit on the spinbox, up to 19.
– Arci Jeirico Malabanan
Jan 4 at 7:48
'%.19f' % x
formats float numbers to 19 digits– BlackBear
Jan 4 at 7:51
'%.19f' % x
formats float numbers to 19 digits– BlackBear
Jan 4 at 7:51
|
show 2 more comments
1 Answer
1
active
oldest
votes
The Python package to-precision
does the job, as per this answer.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54034844%2fexponential-to-float-getting-all-decimal-numbers-of-float%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The Python package to-precision
does the job, as per this answer.
add a comment |
The Python package to-precision
does the job, as per this answer.
add a comment |
The Python package to-precision
does the job, as per this answer.
The Python package to-precision
does the job, as per this answer.
answered Jan 4 at 9:09
Michael GechtMichael Gecht
549718
549718
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54034844%2fexponential-to-float-getting-all-decimal-numbers-of-float%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1e-9 and 0.000000009 are the same number, just written in a different way. Are you asking how to
print
in one format or the other?– BlackBear
Jan 4 at 7:42
in 0.000000009 format. Because when I print the number, it's in 1e-9
– Arci Jeirico Malabanan
Jan 4 at 7:43
4
All decimal places? Really? What if the value is e.g. π, or even something simpler, like 1/3?
– zvone
Jan 4 at 7:44
I have a number char limit on the spinbox, up to 19.
– Arci Jeirico Malabanan
Jan 4 at 7:48
'%.19f' % x
formats float numbers to 19 digits– BlackBear
Jan 4 at 7:51