Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: convert double to string
Replies: 1   Last Post: Dec 29, 2013 10:00 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Nasser Abbasi

Posts: 5,596
Registered: 2/7/05
Re: convert double to string
Posted: Dec 29, 2013 10:00 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 12/29/2013 5:04 AM, fatemeh wrote:
> I want convert double number like 0.222833 to string but when
>i using num2str the number convert to '0.22283' and sixth digit
>of number is removed ,can u help me to convert it to string?
>


just be carful, what you see in the screen is not always the
actual binary value of the number.

EDU>> n=rand(1,1)
n =
0.8147

EDU>> format long
EDU>> n
n =
0.814723686393179

EDU>> num2strexact(n)

0.81472368639317893634910205946653150022029876708984375

EDU>>

One way to convert to string: decide on the number of
digits you want, and you can use sprintf:

EDU>> s=sprintf('%3.10f',n)

0.8147236864

EDU>> s=sprintf('%3.16f',n)
0.8147236863931789

or you can use num2str second argument:

EDU>> num2str(n,10)
0.8147236864

EDU>> num2str(n,16)
0.8147236863931789


--Nasser









Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.