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

笑着哭i 提交于 2019-11-27 06:18:34

问题


I have this problem that has been bothering me for quite a while.. I want to change the format of the number.. Don`t know how? Ive tried the help files but can't find the answer.. If you can help me please do..


回答1:


There are three different things you could potentially be referring to when you talk about the "format" of a number: the display format, the variable storage format in memory (i.e. the data type/class), and the storage format in a data file. I'll address each...

  • Display format: As already mentioned by Amro, the display format can be adjusted with the FORMAT command. However, this only affects how the numbers are displayed, not how they are stored in memory.

  • Variable types/classes: There are a number of numeric classes, both floating point and signed/unsigned integer types, that 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 recast a value. For example, a = uint8(0); converts 0 to an 8-bit unsigned integer type and stores it in a, while b = single(pi); converts the value pi into single-precision and stores it in b.

  • File storage format: When reading/writing numeric values to files, the type of file affects how it will be stored. A binary file (written to and read from using FWRITE and FREAD) stores the complete binary representation of a number, and can thus represent it as exactly the same type as it is stored in memory as a variable (double-precision, single-precision, 8-bit integer, etc.).

    Alternatively, a text file (written to and read from using FPRINTF and FSCANF, among other functions) will store a value in a string format that you must specify when outputting the values to the file. You can specify the digits of precision, as well as the format (such as exponential notation or hexadecimal). The documentation for FPRINTF specifies these output formats.




回答2:


Use the format command

Example:

format long; pi
   3.141592653589793
format short e; pi
   3.1416e+000
format short g; pi
   3.1416



回答3:


sprintf('%.2f', 1.4795e4);

(in particular: if you want it displayed/saved/printed a certain way, be explicit about it!)



来源:https://stackoverflow.com/questions/1480177/how-do-i-go-from-1-4795e004-to-14795-00

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!