如何将整数舍入到最接近的十的倍数?
我试过integer.round(0.1)但它给出了最接近的十进制数.
示例:3应该返回0,55应该返回60.
有没有一种方法可以舍入到最接近的10的倍数?
我只是对DNS的RFC中某些变量的命名法感到好奇:https://www.ietf.org/rfc/rfc1035.txt
虽然我能找到大多数其他缩略词:
我想知道" QD COUNT" 中" QD "代表什么?
当我运行以下代码时:
def db(y)
return self % y == 0
end
puts "To number:"
n = gets.chomp
for i in 1..n
if i.db(3)
puts "Fizz!"
if i.db(5)
puts "FIZZBUZZ!"
end
elsif i.db(5)
puts "Buzz!"
else
puts i
end
end
Run Code Online (Sandbox Code Playgroud)
我得到了"范围错误值"错误.为什么会发生这种情况我该怎么办呢?对某些值使用变量的正常范围可以完美地工作,包括for循环,为什么这不起作用?
注意:我希望for循环保持为for循环.
我试图将if-elif-else语句压缩成一行.我试过了:
a == 1 ? print "one" : a == 2 ? print "two" : print "none"
Run Code Online (Sandbox Code Playgroud)
但是我遇到了语法错误.我也尝试过:
print "one" if a == 1 else print "two" if a == 2 else print "none"
Run Code Online (Sandbox Code Playgroud)
但我也遇到了语法错误.
我可以做些什么来更好地解决这些问题或创建一个有效的答案?
当我运行此代码时,它会在Chrome中出现语法错误.
var leanboo = confirm("RFT(ready for testing)?") // Co1,Cr1
console.log(leanboo)
var text = prompt("What are your thoughts of this Area?")
console.log(text)
function crashCourseTesterIdGenerator(min, max) {
console.log(Math.floor((Math.random() * max) + min);)
} //Co1,Cr2
var testermin = prompt("Id generating min:")
var testermax = prompt("Id generating max:")
console.log(crashCourseTesterIdGenerator(testermin, testermax))
Run Code Online (Sandbox Code Playgroud)
它是否与方法名称长度有关或我只是忘记了一些分号?
我正在尝试获取元素的类,但我不知道将执行它的方法.HTML:
<div class="one"></div>
Run Code Online (Sandbox Code Playgroud)
jQuery的:
$(document).ready(function() {
var divclass = // Over here
console.log(divclass)
});
Run Code Online (Sandbox Code Playgroud)
谁能帮我?注意:我正在尝试使用类"one"记录div的类.
javascript ×2
ruby ×2
class ×1
dns ×1
if-statement ×1
jquery ×1
loops ×1
nomenclature ×1
python ×1
range ×1
rfc ×1
rfc1035 ×1
rounding ×1
variables ×1