How to convert floating point decimal separator from dot to comma in Javascript

chrysst

I have already tried the following:

discval = 2.833423
discval = discval.toFixed(2).toString().replace("." , ",");
discval = parseFloat(discval);

The output is 2 and not 2,83

Any idea?

pawel

parseFloat("2,83") will return 2 because , is not recognized as decimal separator, while . is.

If you want to round the number to 2 decimal places just use parseFloat(discval.toFixed(2)) or Math.round(discval * 100) / 100;

If you need this jut for display purposes, then leave it as a string with a comma. You can also use Number.toLocaleString() to format numbers for display purposes. But you won't be able to use it in further calculations.

BTW .toFixed() returns a string, so no need to use .toString() after that.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to change the decimal separator from a comma to a dot in SQL Server

From Java

Pandas convert numbers with a comma instead of the point for the decimal separator from objects to numbers

From Dev

How to accept both dot and comma as a decimal separator with WTForms?

From Dev

NumericUpDown: accept both comma and dot as decimal separator

From Dev

NumericUpDown: accept both comma and dot as decimal separator

From Dev

Show comma instead of point as decimal separator

From Dev

Show comma instead of point as decimal separator

From Dev

bc: decimal separator comma vs. point

From Dev

Java floating point number in comma instead of dot

From Dev

How to change decimal separator from comma to fullstop in redshift copy command

From Dev

Convert a double to 2 decimal places with comma separator

From Dev

Convert a double to 2 decimal places with comma separator

From Dev

Pasting decimal numbers in excel / comma and point decimal separator

From Dev

How does computer convert floating point numbers to decimal string?

From Dev

How to convert decimal to IEEE double precision floating point binary in Matlab?

From Dev

How to Convert a parseFloat string number to a floating point with 2 decimal places

From Dev

How does computer convert floating point numbers to decimal string?

From Dev

Parsing numbers with a comma decimal separator in JavaScript

From Dev

JavaScript regex to accept numbers with comma separator (thousands) and dot separator (decimals)

From Dev

How to convert point to comma for any number of decimal places

From Dev

In common lisp how can I format a floating point and specify grouping, group char and decimal separator char

From Dev

How to make InvariantCulture recognize a comma as a decimal separator?

From Dev

How to set the floating point symbol in JSpinner to dot instead of comma if the locale is french?

From Dev

Difference between decimal number with comma and dot Javascript

From Dev

Java: convert floating point binary to floating point decimal

From Dev

How to convert number into decimal with shifted decimal separator?

From Dev

Convert floating point numbers to decimal numbers

From Dev

parse double from file with random comma or dot separator

From Dev

parse double from file with random comma or dot separator

Related Related

  1. 1

    How to change the decimal separator from a comma to a dot in SQL Server

  2. 2

    Pandas convert numbers with a comma instead of the point for the decimal separator from objects to numbers

  3. 3

    How to accept both dot and comma as a decimal separator with WTForms?

  4. 4

    NumericUpDown: accept both comma and dot as decimal separator

  5. 5

    NumericUpDown: accept both comma and dot as decimal separator

  6. 6

    Show comma instead of point as decimal separator

  7. 7

    Show comma instead of point as decimal separator

  8. 8

    bc: decimal separator comma vs. point

  9. 9

    Java floating point number in comma instead of dot

  10. 10

    How to change decimal separator from comma to fullstop in redshift copy command

  11. 11

    Convert a double to 2 decimal places with comma separator

  12. 12

    Convert a double to 2 decimal places with comma separator

  13. 13

    Pasting decimal numbers in excel / comma and point decimal separator

  14. 14

    How does computer convert floating point numbers to decimal string?

  15. 15

    How to convert decimal to IEEE double precision floating point binary in Matlab?

  16. 16

    How to Convert a parseFloat string number to a floating point with 2 decimal places

  17. 17

    How does computer convert floating point numbers to decimal string?

  18. 18

    Parsing numbers with a comma decimal separator in JavaScript

  19. 19

    JavaScript regex to accept numbers with comma separator (thousands) and dot separator (decimals)

  20. 20

    How to convert point to comma for any number of decimal places

  21. 21

    In common lisp how can I format a floating point and specify grouping, group char and decimal separator char

  22. 22

    How to make InvariantCulture recognize a comma as a decimal separator?

  23. 23

    How to set the floating point symbol in JSpinner to dot instead of comma if the locale is french?

  24. 24

    Difference between decimal number with comma and dot Javascript

  25. 25

    Java: convert floating point binary to floating point decimal

  26. 26

    How to convert number into decimal with shifted decimal separator?

  27. 27

    Convert floating point numbers to decimal numbers

  28. 28

    parse double from file with random comma or dot separator

  29. 29

    parse double from file with random comma or dot separator

HotTag

Archive