Effacer les filtres
Effacer les filtres

point decimal to comma

18 vues (au cours des 30 derniers jours)
Krasimir Terziev
Krasimir Terziev le 22 Avr 2020
Commenté : Stephen23 le 23 Avr 2020
how i can get my result in matlab editor with comma decimal ? i need just to see my result in command window with a comma :)
  3 commentaires
darova
darova le 22 Avr 2020
This didn't work for me
dpb
dpb le 22 Avr 2020
Can't read the tiny images to tell what didn't work, but Rik's code works fine in the command window (or as code in function as edited and then executed).
>> n=pi;
>> strrep(sprintf('%.4f',n),'.',',')
ans =
'3,1416'
>>
But, as he says, there's no way I know of to change the behavior in MATLAB to use comma instead of decimal directly.
I thought that was what OS LOCALE settings were for and the idea is that applications were to be written to honor those settings/preferences and deal with transparently. BUT AFAIK, that ideal isn't in MATLAB (if it is in any large app of the ilk; I don't know; never had the opportunity to try/test it).

Connectez-vous pour commenter.

Réponses (1)

Rik
Rik le 22 Avr 2020
So in summary: Matlab doesn't check the operating system's locale setting to determine the decimal separator. This question seems to suggest this behavior did actually happen in some situations, but it was (also?) a bug. There is even a doc page that suggests Mathworks will never change this behavior.
As a fallback you can convert a value to a char representation and use strrep on the result:
strrep(sprintf('%.4f',n),'.',',')
%or let Matlab determine an appropriate FormatSpec:
%strrep(num2str(n),'.',',')
The reason for these choices has probably to with code portability: now Matlab doesn't have to worry about the OS settings to interpret a plain text .m file. They could potentially allow it in live scripts, since those aren't plain text. I doubt you will convince them, so you might have to buy Mathworks or otherwise offer unreasonable amounts of money to have this implemented.
  2 commentaires
dpb
dpb le 23 Avr 2020
Modifié(e) : dpb le 23 Avr 2020
The only concession TMW has made so far is the new(ish) readXXX routines... readmatrix and readvars are the two I can think of now that have name-value pairs of 'Decimal|ThousandsSeparator' to define the behavior for text files.
I'm sure it's a nightmare to try to support their code base that began before anybody in US cared there was such a thing as Europe as a potential market for software; what more try to adapt to them furriners' ways...
I'd be much more pleased if they would just bring complex variables up to full-fledged citizen status. For a scientific-oriented package with a Fortran start, would think 30 years would have been long enough.
Stephen23
Stephen23 le 23 Avr 2020
Changing to a decimal comma would then require redefining the comma-separated list separator (otherwise how to interpret max(1,2) ?). If we follow MS Excel's lead the list separator could be the semi-colon, in which case the semi-colon for matrix construction also needs to be redefined.. .to what? There might be other required changes too... it certainly would not be a trivial change to the language.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by