我正在尝试将float值转换为Integer,但无法将其转换。它说找不到符号。有什么方法可以做到这一点。
这是我的Java代码:
float upper = 999999;
float lower = 100000;
Integer ReceiptNo = 0;
Random rnd = new Random();
ReceiptNo = Math.round((Math.floor( (upper - lower + 1) * rnd() ) )) + lower;
这是我的vb代码:
Dim upper As Single = 999999 'Set the upper limit of random number.
Dim lower As Single = 100000
Dim ReceiptNo As Integer = 0
Randomize() 'Need to randomise the random number or else the number generated is always the same
ReceiptNo = CInt(Math.Floor((upper - lower + 1) * Rnd())) + lower
我试图重用Java中的VB代码。谢谢。
最佳答案
rnd
是实例变量,而不是方法,因此您不能编写rnd()
。
你可以写 :
ReceiptNo = (int)(Math.round((Math.floor( (upper - lower + 1) * Math.random() ) )) + lower);
我不确定
Rnd()
在VB中的作用,但是如果它产生0到1之间的随机双精度值,那就是Math.random()
的作用。