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: 6,064
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 =

EDU>> format long
EDU>> n
n =

EDU>> num2strexact(n)



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)


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

or you can use num2str second argument:

EDU>> num2str(n,10)

EDU>> num2str(n,16)


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

[Privacy Policy] [Terms of Use]

© The Math Forum 1994-2015. All Rights Reserved.