## Numeric Calculations

SQL can be used as a numeric calculator.

Following is a list of commonly used functions that can be used in numeric calculations (Click on a function to open the Firebird Reference Manual):

• cast() - CAST converts an expression to the desired datatype or domain. If the conversion is not possible, an error is raised.
• ceiling() - Returns the smallest whole number greater than or equal to the argument.
• floor() - Returns the largest whole number smaller than or equal to the argument.
• iif() - Takes three arguments. If the first evaluates to true, the second argument is returned; otherwise the third is returned.
• maxvalue() - Returns the maximum value from a list of numerical, string, or date/time expressions. This function fully supports text BLOBs of any length and character set.
• minvalue() - Returns the minimum value from a list of numerical, string, or date/time expressions. This function fully supports text BLOBs of any length and character set.
• pi() - Returns an approximation of the value of pi.
• round() - Rounds a number to the nearest integer. If the fractional part is exactly 0.5, rounding is upward for positive numbers and downward for negative numbers. With the optional scale argument, the number can be rounded to powers-of-ten multiples (tens, hundreds, tenths, hundredths, etc.) instead of just integers.

## Using Firebird as a Calculator

You do not need to use tables and fields in order to perform calculations in Firebird. You can run a calculation using the select [CALCULATION] from RDB\$DATABASE format as in the example below.

 `select ``(``2` `+ ``3``) * ``6``from RDB\$DATABASE`

### Notes

If a null value is passed into a calculation, the result will always be null.

The result of a calculation will be of the same data type as the values that were passed into the calculation - eg. 6/4 = 1 and cast(6 as float) / cast(4 as float) = 1.5
{"ft_lang_label":"__label__en","ft_lang_prob":0.75938797,"math_prob":0.98904467,"size":1883,"snap":"2019-51-2020-05","text_gpt3_token_len":426,"char_repetition_ratio":0.121873334,"word_repetition_ratio":0.13622291,"special_character_ratio":0.22942114,"punctuation_ratio":0.10541311,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99080646,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-12-06T15:04:19Z\",\"WARC-Record-ID\":\"<urn:uuid:2e4ffeb0-6b9c-4eec-85ec-8a73bf1dca1b>\",\"Content-Length\":\"60523\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:b0b05efc-13b9-4c5e-9c82-9de74e64182c>\",\"WARC-Concurrent-To\":\"<urn:uuid:0bf47481-4b13-46dc-a197-af0e3e45cab4>\",\"WARC-IP-Address\":\"104.27.168.84\",\"WARC-Target-URI\":\"https://www.quickeasysoftware.com/numeric-calculations/\",\"WARC-Payload-Digest\":\"sha1:N5YLFMEX72A65DSJBNLDI3V5LSIRIC4F\",\"WARC-Block-Digest\":\"sha1:D5N6BGBJBKJDMBTII7NHOIMZ375PF3IV\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-51/CC-MAIN-2019-51_segments_1575540488870.33_warc_CC-MAIN-20191206145958-20191206173958-00248.warc.gz\"}"}