Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downcasting from Object to BigDecimal incorrectly uses Number#longValue #217

Closed
Zoe-hz opened this issue Sep 29, 2020 · 5 comments
Closed
Labels

Comments

@Zoe-hz
Copy link

Zoe-hz commented Sep 29, 2020

} else if (targetType.getType() == BigDecimal.class) { return (SimpleTypeCaster)(JavaClassHelper.isFloatingPointClass(fromType) ? SimpleTypeCasterFactory.BigDecDoubleCaster.INSTANCE : SimpleTypeCasterFactory.BigDecLongCaster.INSTANCE); } else {

public static boolean isFloatingPointClass(Class<?> clazz) { return clazz == Float.class || clazz == Double.class || clazz == Float.TYPE || clazz == Double.TYPE; }

@raguessner
Copy link
Contributor

Without EPL I cannot understand what you are saying

@Zoe-hz
Copy link
Author

Zoe-hz commented Oct 9, 2020

Event class:
public class MyEvent {
private Object[] params;
}

MyEvent myEvent = new MyEvent();
myEvent.setParams(new Object[]{new BigDecimal("156.78"), "CNY"});

then sendEventBean ...

EPL:
select cast(params[0], BigDecimal) as money from MyEvent;

The result is 156 instead of 156.78

Decimal places will be lost in this case, because used BigDecLongCaster instead of BigDecDoubleCaster.

esper version 8.6.0

@bernhardttom bernhardttom changed the title The cast function use BigDecLongCaster to cast a Object(inner is BigDecimal) type to BigDecimal Downcasting from Object to BigDecimal incorrectly uses Number#longValue Oct 9, 2020
@bernhardttom
Copy link
Contributor

I think you are saying that downcasting from Object to BigDecimal incorrectly uses Number#longValue?

@Zoe-hz
Copy link
Author

Zoe-hz commented Oct 10, 2020

Yes

@icholy
Copy link
Contributor

icholy commented Oct 10, 2020

Possibly related to #202?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants