Formatting an array into currency

I have an array called MonthlyIncomeLA the values it has are as follows [4.7948e+0.3, 4.9688e+0.3...so on] I used the
format bank
MonthlyInLa
it only showed the values in the command window, how do i get the whole array of MonthlyInLA to change?

4 Comments

Formatting is only a property of the output display; the data values are still and always will be stored internally as double. Otherwise, you couldn't do any mathematical operations on them which would be most inconvenient for most cases.
"how do i get the whole array of MonthlyInLA to change?"
Neither integer nor floating point data types store any formatting information.
Formatting is purely an artifact of how those types are displayed.
so there is no way I can change e+0.3 format to just integers?
Explain where/what you've trying to accomplish here...in the command window, no, there is no format defined that displays variables as integers unless the values are integral; then they will be shown as such (individually, if in an array that isn't fully integral, then the formatting for the array will be used).
>> format short % is four decimal digits
>> p=pi
p =
3.1416
>> format bank % is two digits
>> p
p =
3.14
>> p=round(p) % round to integer, but bank says two decimals
p =
3.00
>> format short % short will show is integer by dropping trailing zeros
>> p
p =
3
>> a=[pi 3] % but not if in an array with a non-integral value
a =
3.1416 3.0000
>>
You can, of course, DISPLAY values as wanted, but that doesn't change their internal representation.
>> fprintf('%3.0f %3d \n',a)
3 3
>>
NB: MATLAB has a peculiarity in that applying a '%d' formatting string to a non-integral value will result in using a '%e' formatting string. This is a safety net in MATLAB; in the C Standard it is undefined behavior (you lied to the compiler by not having a consistent variable type for the format).
So, the question is what behavior are you trying to achieve here?

Sign in to comment.

Answers (0)

Tags

Asked:

on 19 Oct 2021

Commented:

dpb
on 19 Oct 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!