Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

why does this work with %s  RSS feed

 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

why does this work with %s if i want to print only 123..is there any other way with &f?
 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
%b and %s can work with any type of argument.

If you want to print 123 use %.0f
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got the answer.......%s formats an object by calling its toString() method..hence 123.456 is converted into string and printed out......
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!