Filter löschen
Filter löschen

maintain 0 at the start of a number

3 Ansichten (letzte 30 Tage)
Paul Murphy
Paul Murphy am 11 Dez. 2017
Beantwortet: Star Strider am 11 Dez. 2017
I have string of numbers that starts with a 0. I need to convert this to a number (str2num) but maintain the 0 at the start, as it represents a phone number.
example:
>> a = ('0123')
a =
0123
>> b = str2num(a)
b =
123
Any suggestions on how to do this so that my answer would be 0123?

Akzeptierte Antwort

Star Strider
Star Strider am 11 Dez. 2017
Try this:
a = ('0123');
b = sprintf('%04u', uint64(str2num(a)))

Weitere Antworten (1)

Paul Murphy
Paul Murphy am 11 Dez. 2017
Its a tricky one because i need to first convert the string to a number and then to uint64 as this is the format that my course grader wants the output.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by