Я реализую простой сервис с вводом, где
{ "a": <float>, "b": <float>, "operation": <string>}
Теперь я хочу, чтобы оба
"a": 10
и
"a": 10.0
работали.Если я проверяю только случай с плавающей точкой, я получаю
error: error, message: 'int' cannot be cast to 'float'
, получаю запрос и выполняю следующие действия:
json operationReq = check req.getJsonPayload();
float a = 0;
var intInput = <int>operationReq.a;
match intInput {
int value => a = value;
error err => a = check <float>operationReq.a;
}
Над кодом работает.Но это правильно, или это взлом?