Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Formatting text with percent sign
Formatting text with percent sign [message #49887] Tue, 29 May 2018 13:35 Go to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi,

Feel like a newbie again... How do I use Format to include a percent sign in text like I did with *printf functions:

*printf("Percentage: %.1f %%",15.5);

Results in: "Percentage: 15.5 %"

This does not work:

Format("Percentage: %.1f %%",15.5);

Results in: "Percentage: 15.5 "

Obviously I wish to format special strings with percentage signs in various places, so just having it follow a value is not sufficient.

Best regards,

Tom
Re: Formatting text with percent sign [message #49889 is a reply to message #49887] Wed, 30 May 2018 12:07 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi,

Helping myself, the answer appears to be:

Format("Percentage: %.1f %%%%",15.5);


Maybe someone could add this to the documentation of Format().

Best regards,

Tom

Re: Formatting text with percent sign [message #49890 is a reply to message #49889] Wed, 30 May 2018 15:11 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1075
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello,

I am glad you want to help. Do you have SVN access to commit? If yes you can modify any upp documentation - without any additional privileges.

If not, I can do it for you, but firstly I need to know what to change in documentation. But, I would be happy if you can modify documentation by your own. Moreover, If you do not have SVN access please ask Mirek. Then there will be one more person that can update documentation. What is very important for our library future.

To update documentation using svn you can do something like that:
rm -r -f uppsrc #Please move to the directory when you have uppsrc
svn checkout svn://www.ultimatepp.org/upp/trunk/uppsrc #Replace local copy of uppsrc with the SVN one

# Modify the documentation file in Core using TheIDE and topic editor
cd uppsrc/Core
svn commit -m "Core: Doc: Adding information about escaping percent symbol in Format documentation." # You need to have SVN account to execute that command


Sincerely,
Klugier


U++ - one framework to rule them all.

[Updated on: Wed, 30 May 2018 15:15]

Report message to a moderator

Re: Formatting text with percent sign [message #49893 is a reply to message #49890] Thu, 31 May 2018 18:48 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi,

No, I do not have SVN commit rights to that area, but that's unimportant. You can surely add this tiny bit of information in a suitable place. E.g. in the list of formatting examples table something like:

Format("% %%%%", 12.3)  |  12.3 %


Thanks and best regards,

Tom
Re: Formatting text with percent sign [message #49894 is a reply to message #49893] Thu, 31 May 2018 19:15 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1075
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello,

I added information you had requested. It should be available on our site and in upp distribution tomorrow.

Sincerely,
Klugier


U++ - one framework to rule them all.
Re: Formatting text with percent sign [message #49895 is a reply to message #49887] Thu, 31 May 2018 19:53 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
Hello,

Did the default behaviour change?

On my machine I get (Upp, build 11873, UTF8):

Format("Percentage: %.1f%%",15.5) = Percentage: 15.5%


It works fine here.

Best regards,
Oblivion


[Updated on: Thu, 31 May 2018 20:24]

Report message to a moderator

Re: Formatting text with percent sign [message #49896 is a reply to message #49895] Thu, 31 May 2018 21:05 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi,

I'm beginning to think that I have made a mistake on this one. More specifically, I was basically using an equivalent of printf(Format("% %%%%",12.3)); in a console app. This may well be the reason for needing four percent signs to propagate a single % character all the way through to the console output. I cannot confirm this here at home, but tomorrow at the office I will know.

Klugier, could you please freeze the update to documentation until this can be confirmed? (And if it proves to be just two percent signs (%%) that is needed, like it looks right now, then add that to the documentation instead.)

Oblivion, thanks for pointing out this issue.

Thanks and best regards,

Tom

[Updated on: Thu, 31 May 2018 21:07]

Report message to a moderator

Re: Formatting text with percent sign [message #49897 is a reply to message #49896] Thu, 31 May 2018 22:15 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1075
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello,

I tested Oblivions solution and it works. And then I try to recompile with Tom's example, but it doesn't work:
Cout() << Format("% %%", 12.3) << "\n"; // 12
Cout() << Format("% %%%%", 12.3) << "\n"; // 12 - this doesn't work too, did you test it Tom?

Cout() << Format("%.1f%%", 12.3) << "\n"; // 12.3%
Cout() << Format("%.1f %%", 12.3) << "\n"; // 12.3 %


I think the correct implementation that should be in our documentation is that what Oblivion posted. I updated my todays patch and submitted it to trunk.

URL's:
- Format documentation

Sincerely,
Klugier


U++ - one framework to rule them all.

[Updated on: Thu, 31 May 2018 22:20]

Report message to a moderator

Re: Formatting text with percent sign [message #49898 is a reply to message #49897] Fri, 01 June 2018 08:43 Go to previous message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi,

Yes I can confirm that the standard %% works correctly with Format(). Just as I suspected after being waked up by Oblivion, my use of printf() to output the result from Format() to console caused the issue in the first place:

	Cout() << Format("%.1f %%\r\n",12.3); // yes this works: 12.3 %
	printf(~Format("%.1f %%%%\r\n",12.3)); // and this works: 12.3 %


The documentation this morning looks correct.

Thanks to both of you.

Best regards,

Tom
Previous Topic: Building for Windows XP sp3
Next Topic: Can a ctrl remove itself?
Goto Forum:
  


Current Time: Thu Mar 28 10:31:20 CET 2024

Total time taken to generate the page: 0.01365 seconds