Number Separator

Underscores should be used as thousand separator in large numbers with a configurable number of digits. In other words, there should be an underscore after every 3 digits in the integral as well as the fractional part of a number.

  • Identifier: number_separator
  • Enabled by default: No
  • Supports autocorrection: Yes
  • Kind: style
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity warning
    minimum_length 0
    exclude_ranges []

Non Triggering Examples

let foo = -100
let foo = -1_000
let foo = -1_000_000
let foo = -1.0001
let foo = -1_000_000.0000001
let binary = -0b10000
let binary = -0b1000_0001
let hex = -0xA
let hex = -0xAA_BB
let octal = -0o21
let octal = -0o21_1
let exp = -1_000_000.000000e2
let foo: Double = -(200)
let foo: Double = -(200 / 447.214)
let foo = -6.2832e-6
let foo = +100
let foo = +1_000
let foo = +1_000_000
let foo = +1.0001
let foo = +1_000_000.0000001
let binary = +0b10000
let binary = +0b1000_0001
let hex = +0xA
let hex = +0xAA_BB
let octal = +0o21
let octal = +0o21_1
let exp = +1_000_000.000000e2
let foo: Double = +(200)
let foo: Double = +(200 / 447.214)
let foo = +6.2832e-6
let foo = 100
let foo = 1_000
let foo = 1_000_000
let foo = 1.0001
let foo = 1_000_000.0000001
let binary = 0b10000
let binary = 0b1000_0001
let hex = 0xA
let hex = 0xAA_BB
let octal = 0o21
let octal = 0o21_1
let exp = 1_000_000.000000e2
let foo: Double = (200)
let foo: Double = (200 / 447.214)
let foo = 6.2832e-6

Triggering Examples

let foo = -10_0
let foo = -1000
let foo = -1000e2
let foo = -1000E2
let foo = -1__000
//
// minimum_fraction_length: 3
//

let foo = -1.0001

//
// minimum_fraction_length: 3
//

let foo = -1_000_000.000000_1

let foo = -1000000.000000_1
//
// minimum_fraction_length: 3
//

let foo = -6.2832e-6

let foo = +10_0
let foo = +1000
let foo = +1000e2
let foo = +1000E2
let foo = +1__000
//
// minimum_fraction_length: 3
//

let foo = +1.0001

//
// minimum_fraction_length: 3
//

let foo = +1_000_000.000000_1

let foo = +1000000.000000_1
//
// minimum_fraction_length: 3
//

let foo = +6.2832e-6

let foo = 10_0
let foo = 1000
let foo = 1000e2
let foo = 1000E2
let foo = 1__000
//
// minimum_fraction_length: 3
//

let foo = 1.0001

//
// minimum_fraction_length: 3
//

let foo = 1_000_000.000000_1

let foo = 1000000.000000_1
//
// minimum_fraction_length: 3
//

let foo = 6.2832e-6

let foo: Double = -(100000)
//
// minimum_fraction_length: 3
//

let foo: Double = -(10.000000_1)

//
// minimum_fraction_length: 3
//

let foo: Double = -(123456 / 447.214214)

let foo: Double = +(100000)
//
// minimum_fraction_length: 3
//

let foo: Double = +(10.000000_1)

//
// minimum_fraction_length: 3
//

let foo: Double = +(123456 / 447.214214)

let foo: Double = (100000)
//
// minimum_fraction_length: 3
//

let foo: Double = (10.000000_1)

//
// minimum_fraction_length: 3
//

let foo: Double = (123456 / 447.214214)