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

191
Views
Cómo comparar dos Mongodb tipo primitivo Decimal128 en go
valueA, _ := primitive.ParseDecimal128("123.00") valueB, _ := primitive.ParseDecimal128("123.12")

¿Cómo calcular el valor A < valor B?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Encontré una respuesta gracias a @Matteo

Hay una función que convierte Decimal128 a BigInt.

y BigInt disponibles para comparar

 func CompareDecimal128(d1, d2 primitive.Decimal128) (int, error) { b1, exp1, err := d1.BigInt() if err != nil { return 0, err } b2, exp2, err := d2.BigInt() if err != nil { return 0, err } sign := b1.Sign() if sign != b2.Sign() { if b1.Sign() > 0 { return 1, nil } else { return -1, nil } } if exp1 == exp2 { return b1.Cmp(b2), nil } if sign < 0 { if exp1 < exp2 { return 1, nil } return -1, nil } else { if exp1 < exp2 { return -1, nil } return 1, nil } }

* editado para la parte exponencial

over 4 years ago · Santiago Trujillo Report

0

Mirando en la prueba aquí :

 func compareDecimal128(d1, d2 primitive.Decimal128) bool { d1H, d1L := d1.GetBytes() d2H, d2L := d2.GetBytes() if d1H != d2H { return false } if d1L != d2L { return false } return true }
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!