BBS: Inland Empire Archive Date: 02-05-93 (11:56) Number: 364 From: HERMAN NIEUWENDAAL Refer#: NONE To: CHRIS TRACY Recvd: NO Subj: Re: rounding a number... Conf: (2) Quik_Bas
CT> Does anyone know if there is a routine to actually round a number for CT> real to a certain decimal place? like 3.1415 (hehe) would become CT> 3.142? or something like that.... or have it round up or down... Here's a handy function I ran across that does what you want. >-----------------<CutHere>----------------------------------------------< 'Comment: Rounds a number at the power of 10 decimal place. ' 'Example of Use: x# = Round#(n#, place%) 'Examples: Round#(3.1415#, -3) = 3.142# 'Examples: Round#(3.1415#, -2) = 3.14# 'Examples: Round#(3.1415#, -1) = 3.1# 'Examples: Round#(3.1415#, 0) = 3# ' 'Module Level Declarations: ' DECLARE FUNCTION Round# (n#, place%) FUNCTION Round# (n#, powerOfTen%) STATIC pTen# = 10# ^ powerOfTen% Round# = INT(n# / pTen# + .5#) * pTen# END FUNCTION >-----------------<CutHere>----------------------------------------------< ...Herman --- FMail 0.92 * Origin: Software Heaven (813)653-0029 (1:377/41.0)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET