askql: toInt doesn't convert numbers to integer
π¦ 2.3:toInt
float ask(call(get('toInt'),2.3))
2.3
π¦
Dear Contributor,
This task has evolved a bit. Please read the comments to find out the latest description.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (2 by maintainers)
Great question. Itβs always better to have a few more tests but in case of this resource it will be enough to just write tests in
math.The reason I asked for tests in
askscript/__tests__in a ticket with one of the operators was that an operator was attached to the resource, so I wanted the tests to verify that both the resource and an AskScript-like way of using operators work.@czerwinskilukasz1
I can take this one as per your suggestion.
Ah, OK, understood.
OK, so the task goes as follows:
In case a non-number string or an array or an object is passed to
toInt, it should throw an Error(). Otherwise, it should mimic Math.round() from Javascript.Meaning:
toInt(2.3)returns2toInt('2.3')returns2toInt(2.5)returns3toInt('2.5')returns3toInt(-2.5)returns-2toInt('-2.5')returns-2toInt(-2.51)returns-3toInt('-2.51')returns-3toInt('4a')~returnsNaN~ throws an ErrortoInt('abc')~returnsNaN~ throws an ErrortoInt(true)returns1toInt(false)returns0toInt(null)returns0toInt([])~returns0~ throws an ErrortoInt([1])~returns1~ throws an ErrortoInt([1,2])~returnsNaN~ throws an ErrortoInt({a:1})~returnsNaN~ throws an ErrortoInt({a:1, b: 2})~returnsNaN~ throws an ErrorOK, tickets added π
@czerwinskilukasz1 this should round floats to be integers, I confirm that this is a bug in implementation of
toInt