How do I go from 1.4795e + 004 to 14795.00?

I have this problem that has bothered me for quite some time. I want to change the format of the number. Do not know how? I tried the help files but cannot find the answer. If you can help me, please do ..

+4
source share
3 answers

There are three different things that you could keep in mind when talking about the β€œformat” of a number: the display format, the format for storing variables in memory (ie, the data type / class) and the format for storing a data file. I will review each ...

  • Display Format: As already mentioned by Amro , the display format can be configured using FORMAT . However, this only affects the display of numbers, and not how they are stored in memory.

  • Variable types / classes: There are a number of numerical classes , both floating point and signed / unsigned integer, which variables can use. By default, MATLAB variables are stored as double-precision floating-point numbers. To convert to other types, you can use the variable type as a function to change the value. For example, a = uint8(0); converts 0 to an 8-bit unsigned integer type and stores it in a , and b = single(pi); converts the value of pi to one-point and stores it in b .

  • File storage format: When reading / writing numerical values ​​in files, the file type affects its storage. The binary file (written and read using FWRITE and FREAD ) stores the full binary representation of the number and can thus be represented as exactly the same type that is stored in memory as a variable (double precision, single-point, 8-bit integer, etc. .).

    Alternatively, a text file (written and read using FPRINTF and FSCANF , among other functions) will save the value in a string format, which you must specify when outputting the values ​​to a file. You can specify precision numbers, as well as the format (for example, exponential notation or hexadecimal). The documentation for FPRINTF defines these output formats.

+8
source

Use the format command

An example :

 format long; pi 3.141592653589793 format short e; pi 3.1416e+000 format short g; pi 3.1416 
+6
source
 sprintf('%.2f', 1.4795e4); 

(in particular: if you want it to be displayed / saved / printed in a certain way, be honest with that!)

0
source

All Articles