Reputation: 263
I have a vb6 code which generate the random number. The Query is Like this:
"xyz= Format(10000 * Rnd(-Rnd(-Val(valueData / 10000))), "000000")
I want to convert in to C# code. Currently i am using Dotnet 3.5. "valueData" is a return value and it is a string. In vb6 it is working fine. but in C# when i converting to integer it is not returning any decimal value. But when i change it like bellow i am getting the decimal value but I am not able to pass it to random number function. because it is accepting only integer.
sss= Convert.ToDecimal(valueData ) / 1000000;
I meed to convert the above code in to C#. any help will be usefull for me."
Upvotes: 0
Views: 282
Reputation: 54417
Blurgh! Forget that VB6 code altogether. In .NET, create a Random
object and call the appropriate method. The NextDouble
method will return a Double
value d
where 0 <= d
< 1. You can then do whatever scaling or translation or rounding you need to massage that into the desired range. DO NOT at any point convert the number to a String
to get what you want. That's an example of why VB6 gets looked down on by those who use other languages.
Upvotes: 1