我有一个名为button1的按钮。使用工具箱我可以将按钮字体高度设置为double值,使用属性然后使用font,然后是size,我可以设置为30.251。但是当我以编程方式设置它时,我不能写30.251。
$(document).ready(function(){
var runAnimate1 = true;
var runAnimate2 = false;
setInterval(function(){
if(runAnimate1) {
$( "#animate1").animate({
width: [ "toggle", "swing" ],
height: [ "toggle", "swing" ],
opacity: "toggle"
}, 5000, "linear", function() {
runAnimate1 = false;
runAnimate2 = true;
});
}
if(runAnimate2) {
$( "#animate2").animate({
width: [ "toggle", "swing" ],
height: [ "toggle", "swing" ],
opacity: "toggle"
}, 5000, "linear", function() {
runAnimate1 = true;
runAnimate2 = false;
});
}
});
});
问题是什么?我需要一个精确的字体高度值,最多可达3个字母。它显示错误"无法从double转换为float"。
答案 0 :(得分:2)
字体大小是float类型而不是double 尝试:
button1.Font = new Font("Arial", 30.251f, FontStyle.Bold);
或者,如果值在double属性中使用:
button1.Font = new Font("Arial", (float)fontSize, FontStyle.Bold);
或者如果你想早点获得号码
float value=(float)(90.753/3);//the numerator & denominator came from certain computations
或更干净
float value=90.753f/3;//the numerator & denominator came from certain computations