Insert comma/point in a number

4 vues (au cours des 30 derniers jours)
Michela Longhi
Michela Longhi le 12 Déc 2017
Commenté : Star Strider le 12 Déc 2017
I have a temperature data in a char format without comma or point to divide the decimal and I want to insert a point after the second number (staring from the left):
char= 225800 and I want t=22.58
Can someone help me, please?
Thank you
Michela

Réponse acceptée

Star Strider
Star Strider le 12 Déc 2017
I am not certain what you are doing.
I assume ‘char’ is a character vector. If so, this will work:
char = '225800';
t = str2double(char)*1E-4 % Double-Precision Numeric
tstr = sprintf('%.2f', t) % Character Array
t =
22.5800
tstr =
'22.58'
  2 commentaires
Michela Longhi
Michela Longhi le 12 Déc 2017
exaclty what I immagine! Thanks
Star Strider
Star Strider le 12 Déc 2017
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by