11.3. Number Format Conversions

This section describes functions that can be used to format numeric values.

11.3.1. Conversion between formatted decimals

  • apoc.number.format(number) format a long or double using the default system pattern and language to produce a string
  • apoc.number.format(number, pattern) format a long or double using a pattern and the default system language to produce a string
  • apoc.number.format(number, lang) format a long or double using the default system pattern pattern and a language to produce a string
  • apoc.number.format(number, pattern, lang) format a long or double using a pattern and a language to produce a string
  • apoc.number.parseInt(text) parse a text using the default system pattern and language to produce a long
  • apoc.number.parseInt(text, pattern) parse a text using a pattern and the default system language to produce a long
  • apoc.number.parseInt(text, '', lang) parse a text using the default system pattern and a language to produce a long
  • apoc.number.parseInt(text, pattern, lang) parse a text using a pattern and a language to produce a long
  • apoc.number.parseFloat(text) parse a text using the default system pattern and language to produce a double
  • apoc.number.parseFloat(text, pattern) parse a text using a pattern and the default system language to produce a double
  • apoc.number.parseFloat(text,'',lang) parse a text using the default system pattern and a language to produce a double
  • apoc.number.parseFloat(text, pattern, lang) parse a text using a pattern and a language to produce a double
  • The full list of supported values for pattern and lang params is described in DecimalFormat JavaDoc

11.3.2. Examples

The following formats a double value using the default system pattern: 

RETURN apoc.number.format(12345.67) as value;

Table 11.12. Results
Value

12,345.67

The following formats a double value, using . as thousand separator, , as decimal separator, rounding down: 

RETURN apoc.number.format(12345, '#,##0.00;(#,##0.00)', 'it') as value;

Table 11.13. Results
Value

12.345,00

The following formats a double value, using . as thousand separator and , as decimal separator: 

RETURN apoc.number.format(12345.67, '#,##0.00;(#,##0.00)', 'it') as value;

Table 11.14. Results
Value

12.345,67

The following parses a formatted value as an int: 

RETURN apoc.number.parseInt('12.345', '#,##0.00;(#,##0.00)', 'it') as value;

Table 11.15. Results
Value

12345

The following parses a formatted value as a float: 

RETURN apoc.number.parseFloat('12.345,67', '#,##0.00;(#,##0.00)', 'it') as value;

Table 11.16. Results
Value

12345.67

The following formats a non numeric value: 

RETURN apoc.number.format('aaa') AS value;

Table 11.17. Results
Value

null

The following parses a non numeric value: 

RETURN apoc.number.parseInt('aaa') AS value;

Table 11.18. Results
Value

null