Convert decimal to percentage value
Clash Royale CLAN TAG#URR8PPP
How can I convert a given decimal into the respective percentage value with a certain amount of positions q after the comma? The percentage should be rounded with respect to q+1.
For example, I am looking for something like
percentage[position after the comma]given decimal
that produces:
percentage[positions-after-comma = 2]0.12123456: 12.12%
percentage[positions-after-comma = 4]0.12123456: 12.1235%
percentage[positions-after-comma = 4]2.12123456: 212.1235%
percentage[positions-after-comma = 1]0.6789: 67.9%
percentage[positions-after-comma = 5]0.6789: 67.89000%
decimal-number percentage
add a comment |
How can I convert a given decimal into the respective percentage value with a certain amount of positions q after the comma? The percentage should be rounded with respect to q+1.
For example, I am looking for something like
percentage[position after the comma]given decimal
that produces:
percentage[positions-after-comma = 2]0.12123456: 12.12%
percentage[positions-after-comma = 4]0.12123456: 12.1235%
percentage[positions-after-comma = 4]2.12123456: 212.1235%
percentage[positions-after-comma = 1]0.6789: 67.9%
percentage[positions-after-comma = 5]0.6789: 67.89000%
decimal-number percentage
add a comment |
How can I convert a given decimal into the respective percentage value with a certain amount of positions q after the comma? The percentage should be rounded with respect to q+1.
For example, I am looking for something like
percentage[position after the comma]given decimal
that produces:
percentage[positions-after-comma = 2]0.12123456: 12.12%
percentage[positions-after-comma = 4]0.12123456: 12.1235%
percentage[positions-after-comma = 4]2.12123456: 212.1235%
percentage[positions-after-comma = 1]0.6789: 67.9%
percentage[positions-after-comma = 5]0.6789: 67.89000%
decimal-number percentage
How can I convert a given decimal into the respective percentage value with a certain amount of positions q after the comma? The percentage should be rounded with respect to q+1.
For example, I am looking for something like
percentage[position after the comma]given decimal
that produces:
percentage[positions-after-comma = 2]0.12123456: 12.12%
percentage[positions-after-comma = 4]0.12123456: 12.1235%
percentage[positions-after-comma = 4]2.12123456: 212.1235%
percentage[positions-after-comma = 1]0.6789: 67.9%
percentage[positions-after-comma = 5]0.6789: 67.89000%
decimal-number percentage
decimal-number percentage
edited Jan 4 at 16:47
BJPrim
asked Jan 4 at 16:31
BJPrimBJPrim
476
476
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can use the siunitx
package:
documentclassarticle
usepackagesiunitx
newcommandpercentage[2][round-precision = 2]% default precision: 2
SI[round-mode = places,
scientific-notation = fixed, fixed-exponent = 0,
output-decimal-marker=., #1]#2e2percent%
begindocument
percentage0.123456 % -> 12.35 %
percentage[round-precision = 3]0.123456 % -> 12.345 %
enddocument
add a comment |
Your values looks wrong. But beside this:
documentclassarticle
usepackagexfp,xparse
ExplSyntaxOn
int_new:Nl_bjprim_round_int
keys_define:nn bjprim
positions-after-comma .int_set:N = l_bjprim_round_int
NewDocumentCommandpercentage O m
keys_set:nn bjprimpositions-after-comma=2,#1
fpevalround(#2*100,l_bjprim_round_int)%
ExplSyntaxOff
begindocument
percentage[positions-after-comma = 2]0.123456: 12.12%
percentage[positions-after-comma = 4]0.123456: 12.1235%
percentage[positions-after-comma = 4]2.123456: 212.1235%
percentage[positions-after-comma = 1]0.6789: 67.9%
percentage[positions-after-comma = 5]0.6789: 67.89000%
enddocument
If you really want to fill up with zeros you could round with siunitx:
documentclassarticle
usepackagexfp,xparse,siunitx
ExplSyntaxOn
int_new:Nl_bjprim_round_int
keys_define:nn bjprim
positions-after-comma .int_set:N = l_bjprim_round_int
NewDocumentCommandpercentage O m
keys_set:nn bjprimpositions-after-comma=2,#1
num[round-mode = places,round-precision=l_bjprim_round_int]fpeval#2*100%
ExplSyntaxOff
begindocument
percentage[positions-after-comma = 2]0.123456: 12.12%
percentage[positions-after-comma = 4]0.123456: 12.1235%
percentage[positions-after-comma = 4]2.123456: 212.1235%
percentage[positions-after-comma = 1]0.6789: 67.9%
percentage[positions-after-comma = 5]0.6789: 67.89000%
enddocument
This way the optional argument is actually mandatory.
– egreg
Jan 4 at 16:59
@egreg thanks, I changed to O.
– Ulrike Fischer
Jan 4 at 17:05
I am struggling to get your code running. It says: "File `xfp.sty' not found." I am working with Overleaf, can it be that this package is not supported?
– BJPrim
Jan 4 at 17:08
That's not what I meant; if you usepercentage<number>
, the previous value is used, which may or may not be desired.
– egreg
Jan 4 at 17:08
1
You can remove xfp and replace fpeval byfp_eval:n
.
– Ulrike Fischer
Jan 4 at 17:23
|
show 3 more comments
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2ftex.stackexchange.com%2fquestions%2f468597%2fconvert-decimal-to-percentage-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use the siunitx
package:
documentclassarticle
usepackagesiunitx
newcommandpercentage[2][round-precision = 2]% default precision: 2
SI[round-mode = places,
scientific-notation = fixed, fixed-exponent = 0,
output-decimal-marker=., #1]#2e2percent%
begindocument
percentage0.123456 % -> 12.35 %
percentage[round-precision = 3]0.123456 % -> 12.345 %
enddocument
add a comment |
You can use the siunitx
package:
documentclassarticle
usepackagesiunitx
newcommandpercentage[2][round-precision = 2]% default precision: 2
SI[round-mode = places,
scientific-notation = fixed, fixed-exponent = 0,
output-decimal-marker=., #1]#2e2percent%
begindocument
percentage0.123456 % -> 12.35 %
percentage[round-precision = 3]0.123456 % -> 12.345 %
enddocument
add a comment |
You can use the siunitx
package:
documentclassarticle
usepackagesiunitx
newcommandpercentage[2][round-precision = 2]% default precision: 2
SI[round-mode = places,
scientific-notation = fixed, fixed-exponent = 0,
output-decimal-marker=., #1]#2e2percent%
begindocument
percentage0.123456 % -> 12.35 %
percentage[round-precision = 3]0.123456 % -> 12.345 %
enddocument
You can use the siunitx
package:
documentclassarticle
usepackagesiunitx
newcommandpercentage[2][round-precision = 2]% default precision: 2
SI[round-mode = places,
scientific-notation = fixed, fixed-exponent = 0,
output-decimal-marker=., #1]#2e2percent%
begindocument
percentage0.123456 % -> 12.35 %
percentage[round-precision = 3]0.123456 % -> 12.345 %
enddocument
edited Jan 4 at 17:22
answered Jan 4 at 16:48
zetaeffezetaeffe
3165
3165
add a comment |
add a comment |
Your values looks wrong. But beside this:
documentclassarticle
usepackagexfp,xparse
ExplSyntaxOn
int_new:Nl_bjprim_round_int
keys_define:nn bjprim
positions-after-comma .int_set:N = l_bjprim_round_int
NewDocumentCommandpercentage O m
keys_set:nn bjprimpositions-after-comma=2,#1
fpevalround(#2*100,l_bjprim_round_int)%
ExplSyntaxOff
begindocument
percentage[positions-after-comma = 2]0.123456: 12.12%
percentage[positions-after-comma = 4]0.123456: 12.1235%
percentage[positions-after-comma = 4]2.123456: 212.1235%
percentage[positions-after-comma = 1]0.6789: 67.9%
percentage[positions-after-comma = 5]0.6789: 67.89000%
enddocument
If you really want to fill up with zeros you could round with siunitx:
documentclassarticle
usepackagexfp,xparse,siunitx
ExplSyntaxOn
int_new:Nl_bjprim_round_int
keys_define:nn bjprim
positions-after-comma .int_set:N = l_bjprim_round_int
NewDocumentCommandpercentage O m
keys_set:nn bjprimpositions-after-comma=2,#1
num[round-mode = places,round-precision=l_bjprim_round_int]fpeval#2*100%
ExplSyntaxOff
begindocument
percentage[positions-after-comma = 2]0.123456: 12.12%
percentage[positions-after-comma = 4]0.123456: 12.1235%
percentage[positions-after-comma = 4]2.123456: 212.1235%
percentage[positions-after-comma = 1]0.6789: 67.9%
percentage[positions-after-comma = 5]0.6789: 67.89000%
enddocument
This way the optional argument is actually mandatory.
– egreg
Jan 4 at 16:59
@egreg thanks, I changed to O.
– Ulrike Fischer
Jan 4 at 17:05
I am struggling to get your code running. It says: "File `xfp.sty' not found." I am working with Overleaf, can it be that this package is not supported?
– BJPrim
Jan 4 at 17:08
That's not what I meant; if you usepercentage<number>
, the previous value is used, which may or may not be desired.
– egreg
Jan 4 at 17:08
1
You can remove xfp and replace fpeval byfp_eval:n
.
– Ulrike Fischer
Jan 4 at 17:23
|
show 3 more comments
Your values looks wrong. But beside this:
documentclassarticle
usepackagexfp,xparse
ExplSyntaxOn
int_new:Nl_bjprim_round_int
keys_define:nn bjprim
positions-after-comma .int_set:N = l_bjprim_round_int
NewDocumentCommandpercentage O m
keys_set:nn bjprimpositions-after-comma=2,#1
fpevalround(#2*100,l_bjprim_round_int)%
ExplSyntaxOff
begindocument
percentage[positions-after-comma = 2]0.123456: 12.12%
percentage[positions-after-comma = 4]0.123456: 12.1235%
percentage[positions-after-comma = 4]2.123456: 212.1235%
percentage[positions-after-comma = 1]0.6789: 67.9%
percentage[positions-after-comma = 5]0.6789: 67.89000%
enddocument
If you really want to fill up with zeros you could round with siunitx:
documentclassarticle
usepackagexfp,xparse,siunitx
ExplSyntaxOn
int_new:Nl_bjprim_round_int
keys_define:nn bjprim
positions-after-comma .int_set:N = l_bjprim_round_int
NewDocumentCommandpercentage O m
keys_set:nn bjprimpositions-after-comma=2,#1
num[round-mode = places,round-precision=l_bjprim_round_int]fpeval#2*100%
ExplSyntaxOff
begindocument
percentage[positions-after-comma = 2]0.123456: 12.12%
percentage[positions-after-comma = 4]0.123456: 12.1235%
percentage[positions-after-comma = 4]2.123456: 212.1235%
percentage[positions-after-comma = 1]0.6789: 67.9%
percentage[positions-after-comma = 5]0.6789: 67.89000%
enddocument
This way the optional argument is actually mandatory.
– egreg
Jan 4 at 16:59
@egreg thanks, I changed to O.
– Ulrike Fischer
Jan 4 at 17:05
I am struggling to get your code running. It says: "File `xfp.sty' not found." I am working with Overleaf, can it be that this package is not supported?
– BJPrim
Jan 4 at 17:08
That's not what I meant; if you usepercentage<number>
, the previous value is used, which may or may not be desired.
– egreg
Jan 4 at 17:08
1
You can remove xfp and replace fpeval byfp_eval:n
.
– Ulrike Fischer
Jan 4 at 17:23
|
show 3 more comments
Your values looks wrong. But beside this:
documentclassarticle
usepackagexfp,xparse
ExplSyntaxOn
int_new:Nl_bjprim_round_int
keys_define:nn bjprim
positions-after-comma .int_set:N = l_bjprim_round_int
NewDocumentCommandpercentage O m
keys_set:nn bjprimpositions-after-comma=2,#1
fpevalround(#2*100,l_bjprim_round_int)%
ExplSyntaxOff
begindocument
percentage[positions-after-comma = 2]0.123456: 12.12%
percentage[positions-after-comma = 4]0.123456: 12.1235%
percentage[positions-after-comma = 4]2.123456: 212.1235%
percentage[positions-after-comma = 1]0.6789: 67.9%
percentage[positions-after-comma = 5]0.6789: 67.89000%
enddocument
If you really want to fill up with zeros you could round with siunitx:
documentclassarticle
usepackagexfp,xparse,siunitx
ExplSyntaxOn
int_new:Nl_bjprim_round_int
keys_define:nn bjprim
positions-after-comma .int_set:N = l_bjprim_round_int
NewDocumentCommandpercentage O m
keys_set:nn bjprimpositions-after-comma=2,#1
num[round-mode = places,round-precision=l_bjprim_round_int]fpeval#2*100%
ExplSyntaxOff
begindocument
percentage[positions-after-comma = 2]0.123456: 12.12%
percentage[positions-after-comma = 4]0.123456: 12.1235%
percentage[positions-after-comma = 4]2.123456: 212.1235%
percentage[positions-after-comma = 1]0.6789: 67.9%
percentage[positions-after-comma = 5]0.6789: 67.89000%
enddocument
Your values looks wrong. But beside this:
documentclassarticle
usepackagexfp,xparse
ExplSyntaxOn
int_new:Nl_bjprim_round_int
keys_define:nn bjprim
positions-after-comma .int_set:N = l_bjprim_round_int
NewDocumentCommandpercentage O m
keys_set:nn bjprimpositions-after-comma=2,#1
fpevalround(#2*100,l_bjprim_round_int)%
ExplSyntaxOff
begindocument
percentage[positions-after-comma = 2]0.123456: 12.12%
percentage[positions-after-comma = 4]0.123456: 12.1235%
percentage[positions-after-comma = 4]2.123456: 212.1235%
percentage[positions-after-comma = 1]0.6789: 67.9%
percentage[positions-after-comma = 5]0.6789: 67.89000%
enddocument
If you really want to fill up with zeros you could round with siunitx:
documentclassarticle
usepackagexfp,xparse,siunitx
ExplSyntaxOn
int_new:Nl_bjprim_round_int
keys_define:nn bjprim
positions-after-comma .int_set:N = l_bjprim_round_int
NewDocumentCommandpercentage O m
keys_set:nn bjprimpositions-after-comma=2,#1
num[round-mode = places,round-precision=l_bjprim_round_int]fpeval#2*100%
ExplSyntaxOff
begindocument
percentage[positions-after-comma = 2]0.123456: 12.12%
percentage[positions-after-comma = 4]0.123456: 12.1235%
percentage[positions-after-comma = 4]2.123456: 212.1235%
percentage[positions-after-comma = 1]0.6789: 67.9%
percentage[positions-after-comma = 5]0.6789: 67.89000%
enddocument
edited Jan 4 at 17:05
answered Jan 4 at 16:45
Ulrike FischerUlrike Fischer
188k7294673
188k7294673
This way the optional argument is actually mandatory.
– egreg
Jan 4 at 16:59
@egreg thanks, I changed to O.
– Ulrike Fischer
Jan 4 at 17:05
I am struggling to get your code running. It says: "File `xfp.sty' not found." I am working with Overleaf, can it be that this package is not supported?
– BJPrim
Jan 4 at 17:08
That's not what I meant; if you usepercentage<number>
, the previous value is used, which may or may not be desired.
– egreg
Jan 4 at 17:08
1
You can remove xfp and replace fpeval byfp_eval:n
.
– Ulrike Fischer
Jan 4 at 17:23
|
show 3 more comments
This way the optional argument is actually mandatory.
– egreg
Jan 4 at 16:59
@egreg thanks, I changed to O.
– Ulrike Fischer
Jan 4 at 17:05
I am struggling to get your code running. It says: "File `xfp.sty' not found." I am working with Overleaf, can it be that this package is not supported?
– BJPrim
Jan 4 at 17:08
That's not what I meant; if you usepercentage<number>
, the previous value is used, which may or may not be desired.
– egreg
Jan 4 at 17:08
1
You can remove xfp and replace fpeval byfp_eval:n
.
– Ulrike Fischer
Jan 4 at 17:23
This way the optional argument is actually mandatory.
– egreg
Jan 4 at 16:59
This way the optional argument is actually mandatory.
– egreg
Jan 4 at 16:59
@egreg thanks, I changed to O.
– Ulrike Fischer
Jan 4 at 17:05
@egreg thanks, I changed to O.
– Ulrike Fischer
Jan 4 at 17:05
I am struggling to get your code running. It says: "File `xfp.sty' not found." I am working with Overleaf, can it be that this package is not supported?
– BJPrim
Jan 4 at 17:08
I am struggling to get your code running. It says: "File `xfp.sty' not found." I am working with Overleaf, can it be that this package is not supported?
– BJPrim
Jan 4 at 17:08
That's not what I meant; if you use
percentage<number>
, the previous value is used, which may or may not be desired.– egreg
Jan 4 at 17:08
That's not what I meant; if you use
percentage<number>
, the previous value is used, which may or may not be desired.– egreg
Jan 4 at 17:08
1
1
You can remove xfp and replace fpeval by
fp_eval:n
.– Ulrike Fischer
Jan 4 at 17:23
You can remove xfp and replace fpeval by
fp_eval:n
.– Ulrike Fischer
Jan 4 at 17:23
|
show 3 more comments
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- 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%2ftex.stackexchange.com%2fquestions%2f468597%2fconvert-decimal-to-percentage-value%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