EMA Java: example to covert the BigDecimal to OMMReal

Do we have an example that can be referred to convert a Java BigDecimal to OMMReal (mantissa and magnitude) so can be populated in the expression like below:

fieldList.add(EmaFactory.createFieldEntry().real(22, <mantissa>, <magnitude>));

Searched the forum and found one in the question description:

https://community.developers.refinitiv.com/questions/51833/how-to-set-real-fids-to-blank-using-java-ema.html

Tagged:

Best Answer

  • Jirapongse
    Jirapongse ✭✭✭✭✭
    Answer ✓

    @Frederic

    I can't find an example for it. However, you can try this code.

    BigDecimal test = new BigDecimal("125.5831200");
    fieldList.add( EmaFactory.createFieldEntry().real(25, test.unscaledValue().longValue(),  OmmReal.MagnitudeType.EXPONENT_0 - test.scale()));

    BigDecimal::unscaledValue() returns a BigInteget whose value is the unscaled value of this BigDecimal. I think it is mantissa of OMMReal.

    BigDecimal::unscaledValue() returns the scale of this BigDecimal. We need to convert this value to the OMMReal hint (magnitude).

    This is a simple snippet code. It isn't fully tested and doesn't cover all use cases.