From: Joao Silva Date: 2012-10-19T05:34:06+09:00 Subject: Truncate number which ends with 0 decimal Hi All. The question is how I can do to truncate a float number ending in 0. I have an exercise where I truncate a float number to 2 decimals, the problem is that if the decimal ends in 0 instead of return the full number, only returns the first number. For example: 53454545.5459332345 >>> 53454545.54 is OK. Now, this number: 948484747.5000000 >>> 948484747.5 is incorrect because it should be 948484747.50 To truncate the number to 2 decimals I'm using this code: ################################### (number*100).to_i / 100.0 ################################## which works correctly if the truncated decimal number does not end in 0. Other examples: ##################################################################### 857474.555586767 ===> 857474.55 ==> is ok. 857474.50000000 ====> 857474.5 ==> is wrong >> Should be 857474.50 8120384.9876355 ===> 8120384.98 ==> is ok. 8120384.9000000 ===> 8120384.9 ==> is wrong >> Should be 8120384.90 ##################################################################### The question is whether there is some other way, that if the decimal number ends in 0, not truncate the first issue, and I return the full number. Thanks. -- Posted via http://www.ruby-forum.com/.