Search code examples
swiftnegative-numbernegate

Convert positive value to negative value in swift


I want to convert a positive value to a negative value, for example:

let a: Int = 10

turn it to -10, my current idea is just use it to multiple -1

a * -1

I'm not sure if this is proper, any idea?


Solution

  • Just use - operator.

    let negativeA = -a