7 Functions to Format a Number to 2 Decimal Places in MySQL

A common task when working with numbers is to format them to a certain amount of decimal places. Two decimal places seems to be the most common format, but we can format to any number of decimal places we want. MySQL provides us with a number of functions that can help us achieve this.

Below are seven functions that can be used to format a number to two decimal places in MySQL.

Continue reading

Signed vs Unsigned Integers

The integer data type is probably one of the more common data types when working with database management systems (and with computing in general). The integer is a numeric data type that allows us to store certain kinds of numbers.

More specifically, an integer is the number zero (0), a positive natural number (e.g. 1, 2, 3, …) or a negative integer with a minus sign (e.g. −1, −2, −3, …). Integers contain no decimal or fractional part.

However, many computing environments distinguish between signed integers and unsigned integers.

Let’s take a look at the difference between signed integers and unsigned integers.

Continue reading

How TRY_PARSE() Works in SQL Server

In SQL Server, the TRY_PARSE() function returns the result of an expression, translated to the requested data type, or NULL if the conversion fails.

Basically, it works the same as the PARSE() function, except that it returns NULL instead of an error if the cast fails.

Both functions are intended for converting string values to either date/time or number types.

Continue reading

How PARSE() Works in SQL Server

In SQL Server, the PARSE() function returns the result of an expression, translated to the requested data type.

Basically, it enables us to parse a string expression to the specified data type. It’s intended for converting string values to either date/time or number types.

The PARSE() function can be handy when attempting to convert with CAST() or CONVERT() fails. The PARSE() function is able to parse the expression, and this may result in certain values being converted that wouldn’t normally be able to be converted.

Continue reading

Find Out Which Currency Symbol your Session Uses in Oracle

In Oracle Database, the following NLS parameters can be used to determine how currencies are displayed for the current session:

  • NLS_CURRENCY specifies the string to use as the local currency symbol for the L number format element.
  • NLS_ISO_CURRENCY determines what to use for the C format element.
  • NLS_DUAL_CURRENCY specifies what to use for the U format element.

The default value for these is determined by the NLS_TERRITORY parameter.

The L, C, and U number format elements can be used in functions like TO_CHAR() to format a number as a currency.

Continue reading