Need to restrict decimal to 20












0














I am having a scenario where I convert number into user preference string



conv = num.toLocaleString('de-DE', { maximumFractionDigits: 20 })


As I have real long numbers I want to restrict upto 20 decimal points.
But above code is not giving me desired output.



Can anyone please suggest how to achieve same?



Thanks,
Nupur










share|improve this question
























  • What is num? Perhaps it is a string?
    – HerrSerker
    Nov 13 '18 at 9:41










  • The questions should be asking what browser are you using because according to this that could be your problem.
    – Adriani6
    Nov 13 '18 at 9:46










  • You don't say what your problem is. (2/3).toLocaleString("de-DE", { maximumFractionDigits: 20 }) prints 0,6666666666666666 in Firefox so I can speculate you're expecting to squeeze more precision that JavaScript is able to provide.
    – Álvaro González
    Nov 13 '18 at 9:48












  • You should at least provide an example of the number you're putting in, and the output you're expecting. Since double precision float numbers only have 15-17 significant decimal digits, using a value of 20 won't do you any good.
    – Robby Cornelissen
    Nov 13 '18 at 9:48
















0














I am having a scenario where I convert number into user preference string



conv = num.toLocaleString('de-DE', { maximumFractionDigits: 20 })


As I have real long numbers I want to restrict upto 20 decimal points.
But above code is not giving me desired output.



Can anyone please suggest how to achieve same?



Thanks,
Nupur










share|improve this question
























  • What is num? Perhaps it is a string?
    – HerrSerker
    Nov 13 '18 at 9:41










  • The questions should be asking what browser are you using because according to this that could be your problem.
    – Adriani6
    Nov 13 '18 at 9:46










  • You don't say what your problem is. (2/3).toLocaleString("de-DE", { maximumFractionDigits: 20 }) prints 0,6666666666666666 in Firefox so I can speculate you're expecting to squeeze more precision that JavaScript is able to provide.
    – Álvaro González
    Nov 13 '18 at 9:48












  • You should at least provide an example of the number you're putting in, and the output you're expecting. Since double precision float numbers only have 15-17 significant decimal digits, using a value of 20 won't do you any good.
    – Robby Cornelissen
    Nov 13 '18 at 9:48














0












0








0







I am having a scenario where I convert number into user preference string



conv = num.toLocaleString('de-DE', { maximumFractionDigits: 20 })


As I have real long numbers I want to restrict upto 20 decimal points.
But above code is not giving me desired output.



Can anyone please suggest how to achieve same?



Thanks,
Nupur










share|improve this question















I am having a scenario where I convert number into user preference string



conv = num.toLocaleString('de-DE', { maximumFractionDigits: 20 })


As I have real long numbers I want to restrict upto 20 decimal points.
But above code is not giving me desired output.



Can anyone please suggest how to achieve same?



Thanks,
Nupur







javascript locale






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 9:40









Federico klez Culloca

15.6k134275




15.6k134275










asked Nov 13 '18 at 9:39









NupurNupur

36249




36249












  • What is num? Perhaps it is a string?
    – HerrSerker
    Nov 13 '18 at 9:41










  • The questions should be asking what browser are you using because according to this that could be your problem.
    – Adriani6
    Nov 13 '18 at 9:46










  • You don't say what your problem is. (2/3).toLocaleString("de-DE", { maximumFractionDigits: 20 }) prints 0,6666666666666666 in Firefox so I can speculate you're expecting to squeeze more precision that JavaScript is able to provide.
    – Álvaro González
    Nov 13 '18 at 9:48












  • You should at least provide an example of the number you're putting in, and the output you're expecting. Since double precision float numbers only have 15-17 significant decimal digits, using a value of 20 won't do you any good.
    – Robby Cornelissen
    Nov 13 '18 at 9:48


















  • What is num? Perhaps it is a string?
    – HerrSerker
    Nov 13 '18 at 9:41










  • The questions should be asking what browser are you using because according to this that could be your problem.
    – Adriani6
    Nov 13 '18 at 9:46










  • You don't say what your problem is. (2/3).toLocaleString("de-DE", { maximumFractionDigits: 20 }) prints 0,6666666666666666 in Firefox so I can speculate you're expecting to squeeze more precision that JavaScript is able to provide.
    – Álvaro González
    Nov 13 '18 at 9:48












  • You should at least provide an example of the number you're putting in, and the output you're expecting. Since double precision float numbers only have 15-17 significant decimal digits, using a value of 20 won't do you any good.
    – Robby Cornelissen
    Nov 13 '18 at 9:48
















What is num? Perhaps it is a string?
– HerrSerker
Nov 13 '18 at 9:41




What is num? Perhaps it is a string?
– HerrSerker
Nov 13 '18 at 9:41












The questions should be asking what browser are you using because according to this that could be your problem.
– Adriani6
Nov 13 '18 at 9:46




The questions should be asking what browser are you using because according to this that could be your problem.
– Adriani6
Nov 13 '18 at 9:46












You don't say what your problem is. (2/3).toLocaleString("de-DE", { maximumFractionDigits: 20 }) prints 0,6666666666666666 in Firefox so I can speculate you're expecting to squeeze more precision that JavaScript is able to provide.
– Álvaro González
Nov 13 '18 at 9:48






You don't say what your problem is. (2/3).toLocaleString("de-DE", { maximumFractionDigits: 20 }) prints 0,6666666666666666 in Firefox so I can speculate you're expecting to squeeze more precision that JavaScript is able to provide.
– Álvaro González
Nov 13 '18 at 9:48














You should at least provide an example of the number you're putting in, and the output you're expecting. Since double precision float numbers only have 15-17 significant decimal digits, using a value of 20 won't do you any good.
– Robby Cornelissen
Nov 13 '18 at 9:48




You should at least provide an example of the number you're putting in, and the output you're expecting. Since double precision float numbers only have 15-17 significant decimal digits, using a value of 20 won't do you any good.
– Robby Cornelissen
Nov 13 '18 at 9:48












1 Answer
1






active

oldest

votes


















1














The problem lies with the way that floating point numbers are stored in the processor. See Floating Point arithmetic and Double-precision floating-point format.



You cannot have 20 significant decimal places in a number. They will get truncated at the end



See an example:
num = 0.0000000000000000123456; will show as "0,00000000000000001235" and
num = 1.0000000000000000123456; will show as "1,00000000000000000000"



If you want to force exactly 20 fractional digits use this options object:



{minimumFractionDigits: 20, maximumFractionDigits: 20}






share|improve this answer

















  • 1




    The important part: you can force 20 digits but the last ones will be incorrect ((2/3).toLocaleString("de-DE", {minimumFractionDigits: 20, maximumFractionDigits: 20}) prints "0,66666666666666660000").
    – Álvaro González
    Nov 13 '18 at 14:01













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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53277989%2fneed-to-restrict-decimal-to-20%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









1














The problem lies with the way that floating point numbers are stored in the processor. See Floating Point arithmetic and Double-precision floating-point format.



You cannot have 20 significant decimal places in a number. They will get truncated at the end



See an example:
num = 0.0000000000000000123456; will show as "0,00000000000000001235" and
num = 1.0000000000000000123456; will show as "1,00000000000000000000"



If you want to force exactly 20 fractional digits use this options object:



{minimumFractionDigits: 20, maximumFractionDigits: 20}






share|improve this answer

















  • 1




    The important part: you can force 20 digits but the last ones will be incorrect ((2/3).toLocaleString("de-DE", {minimumFractionDigits: 20, maximumFractionDigits: 20}) prints "0,66666666666666660000").
    – Álvaro González
    Nov 13 '18 at 14:01


















1














The problem lies with the way that floating point numbers are stored in the processor. See Floating Point arithmetic and Double-precision floating-point format.



You cannot have 20 significant decimal places in a number. They will get truncated at the end



See an example:
num = 0.0000000000000000123456; will show as "0,00000000000000001235" and
num = 1.0000000000000000123456; will show as "1,00000000000000000000"



If you want to force exactly 20 fractional digits use this options object:



{minimumFractionDigits: 20, maximumFractionDigits: 20}






share|improve this answer

















  • 1




    The important part: you can force 20 digits but the last ones will be incorrect ((2/3).toLocaleString("de-DE", {minimumFractionDigits: 20, maximumFractionDigits: 20}) prints "0,66666666666666660000").
    – Álvaro González
    Nov 13 '18 at 14:01
















1












1








1






The problem lies with the way that floating point numbers are stored in the processor. See Floating Point arithmetic and Double-precision floating-point format.



You cannot have 20 significant decimal places in a number. They will get truncated at the end



See an example:
num = 0.0000000000000000123456; will show as "0,00000000000000001235" and
num = 1.0000000000000000123456; will show as "1,00000000000000000000"



If you want to force exactly 20 fractional digits use this options object:



{minimumFractionDigits: 20, maximumFractionDigits: 20}






share|improve this answer












The problem lies with the way that floating point numbers are stored in the processor. See Floating Point arithmetic and Double-precision floating-point format.



You cannot have 20 significant decimal places in a number. They will get truncated at the end



See an example:
num = 0.0000000000000000123456; will show as "0,00000000000000001235" and
num = 1.0000000000000000123456; will show as "1,00000000000000000000"



If you want to force exactly 20 fractional digits use this options object:



{minimumFractionDigits: 20, maximumFractionDigits: 20}







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 9:49









HerrSerkerHerrSerker

20k84779




20k84779








  • 1




    The important part: you can force 20 digits but the last ones will be incorrect ((2/3).toLocaleString("de-DE", {minimumFractionDigits: 20, maximumFractionDigits: 20}) prints "0,66666666666666660000").
    – Álvaro González
    Nov 13 '18 at 14:01
















  • 1




    The important part: you can force 20 digits but the last ones will be incorrect ((2/3).toLocaleString("de-DE", {minimumFractionDigits: 20, maximumFractionDigits: 20}) prints "0,66666666666666660000").
    – Álvaro González
    Nov 13 '18 at 14:01










1




1




The important part: you can force 20 digits but the last ones will be incorrect ((2/3).toLocaleString("de-DE", {minimumFractionDigits: 20, maximumFractionDigits: 20}) prints "0,66666666666666660000").
– Álvaro González
Nov 13 '18 at 14:01






The important part: you can force 20 digits but the last ones will be incorrect ((2/3).toLocaleString("de-DE", {minimumFractionDigits: 20, maximumFractionDigits: 20}) prints "0,66666666666666660000").
– Álvaro González
Nov 13 '18 at 14:01




















draft saved

draft discarded




















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53277989%2fneed-to-restrict-decimal-to-20%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python