MATLAB: How to extract the first part of a number in standard form/scientific notation

extractfirstformMATLABnotationnumberpartscientificstandard

How can extract the first part of a number that is in scientific notation or standard form?
For example I have a number 2.68e20. How can I extract the 2.68 out from this number?

Best Answer

One of many ways to do this is to:
1. Convert the number into a scientific notation string
2. Split the string using 'e' as the delimiter
3. Convert the first element of the resulting array from the split to a double.
 
x = 346346346^2; % Create some big number
string = sprintf('%.2e', x); % Convert number to a scientific notation string with 2 decimal places of precision
stringParts = strsplit(string,'e'); % Split the string where 'e' is
firstPart = str2double(stringParts(1)); % Get the 1st part of stringParts which is the first part of standard form.