Chen Log

陳洛格

去掉 Float 浮點數字 後面的 0

leave a comment »

如何把 55.0 變成 55?
這是ruby浮點運算常需要遇到的問題。
 

float.to_s.gsub(/(\.?0+$)/,””).gsub(/(\.+)/,”.”)

直接把浮動數字後面多餘的零去掉!

參考網頁:

http://railsforum.com/viewtopic.php?id=24996

Advertisements

Written by chenagw

2013/01/19 at 00:47

Posted in Uncategorized

Tagged with ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: