0

If I set a variable in Matlab, say var1 = 2.111, after running the script, Matlab returns var1 = 2.1110. I want Matlab to return the original number, with no trailing zero. Anyone know how to do this. Thanks in advance.

1 Answers1

1

By default Matlab displays results in Short fixed decimal format, with 4 digits after the decimal point. You can change that to various other format such as:

long
Long fixed decimal format, with 15 digits after the decimal point for double values, and 7 digits after the decimal point for single values. 3.141592653589793

shortE
Short scientific notation, with 4 digits after the decimal point. Integer-valued floating-point numbers with a maximum of 9 digits do not display in scientific notation. 3.1416e+00

longE
Long scientific notation, with 15 digits after the decimal point for double values, and 7 digits after the decimal point for single values. Integer-valued floating-point numbers with a maximum of 9 digits do not display in scientific notation. 3.141592653589793e+00

shortG
The more compact of short fixed decimal or scientific notation, with 5 digits. 3.1416

longG
The more compact of long fixed decimal or scientific notation, with 15 digits for double values, and 7 digits for single values. 3.14159265358979

shortEng
Short engineering notation, with 4 digits after the decimal point, and an exponent that is a multiple of 3. 3.1416e+000

longEng
Long engineering notation, with 15 significant digits, and an exponent that is a multiple of 3. 3.14159265358979e+000

However I don't think other options are available. If you absolutely want to remove those zeros you would have to cast you result in a string and remove the trailing 0 characters and then display your result as a string and not a number.

vrleboss
  • 463
  • 4
  • 24