Rnd() and Round Function in MS Access

1. Rnd() Function :
Rnd() function return the random number.if we want to generate a number between 0 to 1 then use only Rnd. Otherwise, if we want to generate a number between a range then we will use the formula Int ((upperbound – lowerbound + 1) * Rnd + lowerbound).

Syntax :

  • If we want to generate between 0 to 1 –
    Rnd 
  • If we want to generate in a range –
    Int((upperbound - lowerbound + 1) * Rnd + lowerbound) 

Example-1 :

SELECT Int ((10 - 1 + 1) * Rnd + 1) AS RandNumBetween1and10;

Output –

RandNumBetween1and10
8

Example-2 :



SELECT Rnd AS RandNumBetween0and1;

Output –

RandNumBetween0and1
0.705547511577606

2. Round() Function :
Round() function returns rounds a number to a specified number of decimal places.In this function we will pass an expression and the second parameter will be decimal places till that the number will be rounded.

Note :
If the number ends with 5 then this function rounded last digits as even number.

Syntax :

Round(expression, decimal_places)

Example-1 :

SELECT Round(23.67, 1) As round;

Output –

round
23.7

Example-2 :

SELECT Round(45.65, 1) As round;

Output –

round
45.6
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.