doskmc7870 2016-12-20 18:07
浏览 115

我一直收到错误“请求内容格式错误:预期BigDecimal为JsNumber”

I am trying to do an API request based on json and one of the parameters i am supplying (10) should be an integer with 2 decimal places but what i have is a whole number. When i do the api call directly as "amount" => 10.00, it suceeds but when I hold the integer as $amount = $received_amount."00"; where $received_amount = 10; it throws an error as Received error response: The request content was malformed: Expected BigDecimal as JsNumber, but got "10.00"

I have tried most of the methods available changing a whole number by appending 2 decimal places at the end but none seems to work. Any work around?

  • 写回答

1条回答 默认 最新

  • doog1092 2016-12-20 18:26
    关注

    Concatenation is a string construct. You can't concatenate integers or floats.

    10 . '00' would give you a string of '1000'. I'm assuming what you meant was 10 . '.00'.

    You can convert an integer to a float in various ways:

    var_dump(10 + 0.00);
    var_dump( (float) 10 );
    var_dump( floatval(10) );
    

    However, all of these will represent the float as 10 not 10.00 since that is how the float is supposed to be represented in accordance with IEEE754.

    The string format is the only way you'll be able to represent 10.00. So this comes down to how you send it to Javascript which isn't represented in your question.

    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计