Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
你如何在字符串中做减法?我得到零而不是 90%。
#!/bin/ruby puts " some text #{100%10} some text "
在这种情况下,答案为零,因为100%10是 0,即除法的余数是 0。100 可以被 10 整除。也许您打算-改用?
100%10
-
%是 的别名modulo。
%
modulo
10 / 3 #=> 3 10 % 3 #=> 1
我猜你想写:
puts " some text #{100 - 10}% some text "