Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > how to force a decimal

Reply
Thread Tools

how to force a decimal

 
 
shawn bright
Guest
Posts: n/a
 
      06-20-2008
[Note: parts of this message were removed to make it a legal post.]

Hey there all,

This should be simple. I need to know how to force a decimal place.

say i wanted to do 3.5.to_s
but i need that to be 3.50 as the string,

how would i do this?

thanks

 
Reply With Quote
 
 
 
 
ThoML
Guest
Posts: n/a
 
      06-20-2008
> say i wanted to do *3.5.to_s
> but i need that to be 3.50 as the string,


Use String#% and friends:

"%.2f" % 3.5
 
Reply With Quote
 
 
 
 
shawn bright
Guest
Posts: n/a
 
      06-20-2008
[Note: parts of this message were removed to make it a legal post.]

cool, thanks much !

On Fri, Jun 20, 2008 at 1:38 PM, ThoML <(E-Mail Removed)> wrote:

> > say i wanted to do 3.5.to_s
> > but i need that to be 3.50 as the string,

>
> Use String#% and friends:
>
> "%.2f" % 3.5
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Nike air force one, air force 1, air force one low cut, air force one abdul_razak@indiatimes.com Digital Photography 2 12-31-2008 04:29 PM
Nike Air Force Ones,Air Force One Air Force One-1 lky52193@gmail.com Computer Support 0 01-17-2008 04:40 PM
Nike Air Force Ones,Air Force One Air Force One-1,25th anniversary lky52112@gmail.com Digital Photography 0 01-15-2008 04:46 PM
Nike Air Force Ones,Air Force One Air Force One-1,25th anniversary lky52112@gmail.com Digital Photography 0 01-15-2008 04:34 PM



Advertisments