Help! How can I neutralize a BigDecimal?
Here is a bug that was hard to find:
I was doing a json query of address locations using Google's Maps Geocoding API. I fed it a list of 400 city names and it failed on city 335.
The latitude and longitude looked perfectly normal for that city, but I eventually discovered that the class of the longitude was java.math.BigDecimal. All the other latitudes and longitudes were java.lang.Double. For some reason, Google decided to send that one value as a BigDecimal.
NodeBox does not seem to like BigDecimals. The longitude lookup on the json query result returned the value but I can't do anything with it. If I feed it into a number or integer or string node, I get a type mismatch error. If I feed it into a make point node I get a null point error. If I try using a compare node I get "java.lang.Double cannot be cast to java.math.BigDecimal". I can't add 0 to it or round it. I can't cull the list based on class because the equals node gets a type mismatch on class lookups.
Help! Is there anything I can do to neutralize this radioactive number?
Thanks,
John
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by john on 29 Jan, 2017 07:22 AM
In case you want to test this I am attaching an example.
This network takes any address and uses a free Google API to return latitude and longitude, which it plots as a red dot on a grid.
Most city names work fine (London, Paris, etc.). But if you change the city to Slough (a town in the UK near London) you'll get an error. This happens because Google returns a bigDecimal instead of the usual langDouble for Slough's longitude. (To verify this, attach a lookup node to the output of the "longitude" node and set the lookup key to "class".)
I've been thinking what the easiest way to fix this would be. I notice that other languages handle this sort of problem by converting troublesome values to strings, which can then be turned back into supported numerical formats as needed.
I tried doing this with NodeBox, but the string node turned up its nose at a bigDecimal. I think you should be able to cast just about anything to a string. If the string node would accept a bigDouble that would give me a reasonable workaround.
John
Support Staff 2 Posted by john on 09 Feb, 2017 08:24 PM
Anybody there?
Support Staff 3 Posted by john on 27 Feb, 2017 11:01 PM
Is anyone on staff reviewing this forum? This is not an urgent issue, but I would appreciate an acknowledgement that my comments were read and understood.
Do you agree that string nodes should accept all formats including bigDoubles? If so, can you at least add that to the issues list? Or even better, just transparently convert bigDoubles to floating points. Or at least throw a meaningful error.
Also, please see the related thread Geocoding Null Error. This problem has occurred before and is hard to spot.