Round a number in VB-Script
Hi to all. This is my query regarding VB-Script programs. I have few assignments to submit which are for VB-Script. Of which there are a few programs which I am unable to code. Especially the program to Round a Number using VB-Script. Also I want the code to get a random number returned or a random number within a specified range. I am unable to code the program to replace some characters in a string. Help me to code the above mentioned programs and especially as I have mentioned help me with the program to Round a Number using VB-Script.
VBScript Program to round up a number
I also had hard time to code the program to round a number in VBScript programming. But then I learnt about the in-built function of VBScript known as the Round() function. This is the function used to round a number in VBScript. Here is a program using VBScript to round up a number:
HTML Code:
<html>
<body>
<script type="text/vbscript">
a = 37.273095
b = 14.82649
Round Up Value:document.write(Round(a))
Round Up Value:document.write("<br /><br/>")
Round Up Value:document.write(Round(b))
</script>
</body>
</html>
Random Numbers between 0 to 50
The following program will help you to generate Random number in the range of 0 -50.
HTML Code:
<html>
<body>
<script type="text/vbscript">
Randomize()
temp=Int(50 * Rnd())
document.write("A random number: <b>" & temp & "</b>")
</script>
</body>
</html>
The Rnd function will generate a number randomly which is supposed to be a positive number but between 0 and 1. This number is then multiplied to the end value to display random numbers as in the above programs we get random number between 0 to 50.
Rnd( ) to get Random numbers
To get a random number generated in VBScript we can make use of the Rnd(). This Rnd() function will provide you with pseudo-random number. This random number generated by Rnd() function is a value which is positive but cannot be greater the one. We can use this pseudo-random number and multiple with another value to get any pseudo-random number that is less then the provided value.