I wanna change the assigned value format's long in this function (value) "set(handles.edit1, 'String', value)"

%for example x=-0.134635523018792
%for gui presentation
set(handles.edit1, 'String', x)
%in gui x=-0.1346355 %7 numbers after the dot is appeared but I want to see whole numbers after the dot

 채택된 답변

Jan
Jan 2013년 4월 17일
편집: Jan 2013년 4월 17일
It is very surprising that
set(handles.edit1, 'String', x)
shows any string at all, when x is a double value. Actually only strings and cell strings are accepted.
This shows x with 16 digits:
x = -0.134635523018792;
set(handles.edit1, 'String', sprintf('%.16g', x))
Note that it cannot be guaranteed, that you see "all" digits, because there are no accurate decimal representations for the numbers, which are store in binary format internally. See also: FAQ: Why is 0.3-0.2-0.1 ~= 0

댓글 수: 4

dude, it doesn't work, any possible solution?
"It doesn't work" does not contain any details about the occurring problems. I cannot guess, what's going wrong. Therefore I suggest, that you explain the problems with all required details.
Please note, that I do not understand, how the code in the original message could show any string at all, because you set the 'String' property to the non-string x.
I noticed that he said your codes worked well just several minutes ago.
ok no problem, it works thank you very much

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Yao Li
Yao Li 2013년 4월 17일
x='-0.134635523018792';

댓글 수: 4

set(hObject, 'String', num2str(x,'%1.15f'))
Maybe this one is better.
it doesn't work any possible solution you could offer?
Actually, I tried the command on my computer just now and it works well. I don't know why you failed.
ok no problem it works thank you so much

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2013년 4월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by