# Sprintf percent sign problem

**URL:** <https://www.ruby-forum.com/t/sprintf-percent-sign-problem/119172>\
**Category:** Ruby\
**Created:** [November 4, 2007, 9:43am UTC](https://www.ruby-forum.com/t/sprintf-percent-sign-problem/119172 "2007-11-04T09:43:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpthimios](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b3f665/32.png) [@mpthimios](https://www.ruby-forum.com/u/mpthimios)\
**Post date:** [November 4, 2007, 9:43am UTC](https://www.ruby-forum.com/t/sprintf-percent-sign-problem/119172/1 "2007-11-04T09:43:23Z")

</div>

Hi,  
I am trying to format some text using sprintf. The text itself  
contains the percent sign (%).

When I use it without any escape character, as expected ruby throws  
error (unkonown format sequence).

When I use the “%” sequence ruby complaints when the “%” is  
somewhere in the text. When it is at the end it works but I don’t want  
it there.

When I use the “%%” sequence, I get the exact sequence as output ("%%"  
is printed!!)… \

Has anyone observed this behavior? Am I doing something wrong or it is  
a ruby bug?

Thanks in advance,  
Efthimios.

---

<div class="post-metadata">

**Author:** ![mpthimios](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b3f665/32.png) [@mpthimios](https://www.ruby-forum.com/u/mpthimios)\
**Post date:** [November 4, 2007, 1:30pm UTC](https://www.ruby-forum.com/t/sprintf-percent-sign-problem/119172/2 "2007-11-04T13:30:51Z")

</div>

mpthimios wrote:

> When I use the “%%” sequence, I get the exact sequence as output ("%%"  
> is printed!!)… \
> 
> Has anyone observed this behavior? Am I doing something wrong or it is  
> a ruby bug?

I don’t see that:

irb(main):001:0\> text = “foo%%bar”  
=\> “foo%%bar”  
irb(main):002:0\> sprintf(text)  
=\> “foo%bar”

---

<div class="post-metadata">

**Author:** ![mpthimios](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b3f665/32.png) [@mpthimios](https://www.ruby-forum.com/u/mpthimios)\
**Post date:** [November 4, 2007, 10:09am UTC](https://www.ruby-forum.com/t/sprintf-percent-sign-problem/119172/3 "2007-11-04T10:09:38Z")

</div>

Duplicate post. See here:

[http://www.ruby-forum.com/topic/130350#new](http://www.ruby-forum.com/topic/130350#new)
