Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
¿Por qué NSDecimalNumber.notANumber.intValue devuelve 9?

Encontré un error en mi código causado por NSDecimalNumber.notANumber.intValue devuelve 9, mientras que esperaría NaN (como floatValue o doubleValue return). ¿Alguien sabe por qué?

ingrese la descripción de la imagen aquí

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Como lo mencionó Joakim Danielson y se señaló en la Documentación para desarrolladores de Apple

... Debido a que los tipos numéricos tienen diferentes capacidades de almacenamiento, intentar inicializar con un valor de un tipo y acceder al valor de otro tipo puede producir un resultado erróneo...

Y dado que la estructura Int de Swift no puede representar valores de NaN, obtiene este resultado erróneo.

En su lugar, podría usar Int 's Failable Initialiser init(exactly:) que convierte su NSDecimalNumber en un Int? eso contendrá su valor o será nil si no es representable por un Int .

 let strangeNumber = NSDecimalNumber.notANumber // nan let integerRepresentation = Int(exactly: strangeNumber) // nil
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!