Thread Subject: Writing % mark to fprintf statements

Subject: Writing % mark to fprintf statements

From: Jack Branning

Date: 5 Jun, 2008 10:40:06

Message: 1 of 6

Hi there,

Does anyone know how I can write a % sign to an fprintf statement. I have a
number that I need to express as a percentage:

fprintf(1, '\nHash length is: %2.2f percent of previous hash\n', hash_size);

but I want to change 'percent' to '%' so that it is more readable.

Any suggestions.

Many thanks.

Subject: Writing % mark to fprintf statements

From: French Caro

Date: 5 Jun, 2008 11:39:01

Message: 2 of 6

"Jack Branning" <jbr.nospam@nospam.com> wrote in message
<g28fq6$gte$1@fred.mathworks.com>...
> Hi there,
>
> Does anyone know how I can write a % sign to an fprintf
statement. I have a
> number that I need to express as a percentage:
>
> fprintf(1, '\nHash length is: %2.2f percent of previous
hash\n', hash_size);
>
> but I want to change 'percent' to '%' so that it is more
readable.
>
> Any suggestions.
>
> Many thanks.
Hi,

Just put %% :
fprintf(1, '\nHash length is: %2.2f %% of previous hash\n',
hash_size);

Caroline

Subject: Writing % mark to fprintf statements

From: Ken Prager

Date: 5 Jun, 2008 11:46:37

Message: 3 of 6

In article <g28fq6$gte$1@fred.mathworks.com>,
 "Jack Branning" <jbr.nospam@nospam.com> wrote:

> fprintf(1, '\nHash length is: %2.2f percent of previous hash\n', hash_size);


Use %%, as in

fprintf(1, '\nHash length is: %2.2f %% of previous hash\n', hash_size);

HTH,

KP

Subject: Writing % mark to fprintf statements

From: shlomi laufer

Date: 5 Jun, 2008 11:50:03

Message: 4 of 6

"Jack Branning" <jbr.nospam@nospam.com> wrote in message
<g28fq6$gte$1@fred.mathworks.com>...
> Hi there,
>
> Does anyone know how I can write a % sign to an fprintf
statement. I have a
> number that I need to express as a percentage:
>
> fprintf(1, '\nHash length is: %2.2f percent of previous
hash\n', hash_size);
>
> but I want to change 'percent' to '%' so that it is more
readable.
>
> Any suggestions.
>
> Many thanks.
Hi,
You need to write it twice (%%) :
fprintf(1,'\nHash length is: %2.2f %% of previous hash\n',
hash_size);
or a work around
a = '%';
fprintf(1,'\nHash length is: %2.2f %c of previous hash\n',
hash_size,a);
 The first way make more sence.

Subject: Writing % mark to fprintf statements

From: Steven Lord

Date: 5 Jun, 2008 13:31:19

Message: 5 of 6


"Jack Branning" <jbr.nospam@nospam.com> wrote in message
news:g28fq6$gte$1@fred.mathworks.com...
> Hi there,
>
> Does anyone know how I can write a % sign to an fprintf statement. I have
> a
> number that I need to express as a percentage:
>
> fprintf(1, '\nHash length is: %2.2f percent of previous hash\n',
> hash_size);
>
> but I want to change 'percent' to '%' so that it is more readable.
>
> Any suggestions.
>
> Many thanks.

As others have posted, you'll need to use the escape character %% to display
the percent sign in your string. For future reference, there is a list of
the escape characters (which includes %%) in the documentation for FPRINTF:

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/fprintf.html

--
Steve Lord
slord@mathworks.com

Subject: Writing % mark to fprintf statements

From: Jack Branning

Date: 5 Jun, 2008 15:03:05

Message: 6 of 6

Thank you all for your help. I will bear the escape characters in mind for next
time.

I tried looking for it in the documentation, but I didn't know what to search for,
but now I do.

Thanks again!

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
fprintf Jack Branning 5 Jun, 2008 06:45:04
percentages Jack Branning 5 Jun, 2008 06:45:04
rssFeed for this Thread

Contact us at files@mathworks.com