Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save CharlesLuxinger/fccd2e020e1147b26b71c84d007faf7b to your computer and use it in GitHub Desktop.
Save CharlesLuxinger/fccd2e020e1147b26b71c84d007faf7b to your computer and use it in GitHub Desktop.
BigDecimal To Decimal128 Mongo Converter
package br.com.soudonus.credit.port.config.converter
import java.math.BigDecimal
import java.math.RoundingMode
import org.bson.types.Decimal128
import org.springframework.core.convert.converter.Converter
object BigDecimalToDecimal128Converter {
fun decimal128ToBigDecimal(): Converter<Decimal128, BigDecimal> =
Converter<Decimal128, BigDecimal> { decimal128 -> decimal128.bigDecimalValue() }
fun bigDecimalToDecimal128(): Converter<BigDecimal, Decimal128> =
Converter<BigDecimal, Decimal128> { bigDecimal -> Decimal128(bigDecimal.setScale(2, RoundingMode.HALF_EVEN)) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment