0

Hello im having a problem with my flash file. I have a value where when u press a button it raise by 0.2 but when i have raised it 3 times so it equals 0.6 but when i put the variable inside a text box it shows the following (times i have raised the value by clicking the button):
1: 0.2
2: 0.4
3: 0.6000000000000000
4: 0.8
5: 1
6: 1.2
7: 1.4
8: 1.5999999999999999

so for some reason it dosent raise by 0.2 or it do but not all the time... so can anyone help me how to set the max length of a value or how to fix this? so it raise by 0.2 every time :)

my code for the button:

shop_1.addEventListener(MouseEvent.MOUSE_UP,shop_1_c);
function shop_1_c(e:MouseEvent){
    if(ep >= 25){
    ep_per_second = ep_per_second+0.2;
    ep = ep-25;
    }
4

1 回答 1

3

看看Number.toFixed()。这将允许您选择一个数字中有多少位。这将返回四舍五入到参数中指定的小数位的数字的字符串版本。字符串中的值可能与原始数字中的值不同(即3.18.toFixed(1) = "3.2",不是 3.1 或 3.18)

如果用户正在输入值,您还可以查看TextField.maxChars,这将限制可以在 TextField 中输入的字符数(大多数其他文本输入也具有相同的属性)。

于 2013-11-14T18:29:36.293 回答