如何将传入的JSON值转换为小数 [英] How do I convert an incoming JSON value to a decimal

查看:875
本文介绍了如何将传入的JSON值转换为小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿。难倒在这里。



我有一个JSON字符串从支付API返回数据,它通过PHP实现到我的html代码中:



问题是API仅在API端没有十进制转换时提取数值。我的系统正在将数字转换为小数,这是小数点后的一位小数。



例如:

返回API:总计:500(未转换为json值)

总计:$ 500.00(我看到的)

总计:$ 5.00(我想要的)



以下是我在HTML文件中用来显示数据的代码片段。



Hey. Stumped over here.

I have a JSON string returning data from a payment API, it is implemented into my html code via PHP:

The issue is that the API pulls in number values only with no decimal conversion on the API end. My system is converting the number to a decimal which is one decimal place off from where it should be.

For example:
Returned from API: Total: 500 (Not converted json value)
Total: $500.00 (What I see)
Total: $5.00 (What I want)

Here is the snippet of code that I am using in my HTML file to show the data.

<?php echo ((isset($processData['original_total_charged']) && !empty($processData['original_total_charged'])) ? $this->Number->currency($processData['original_total_charged'], Configure::read('PAYMENT_SETTINGS.Currency')): ""); ?>





original_total_charged是数字字符串的id被退回。



我的问题在哪里?我觉得我明白这个问题是什么;但我不知道我犯了哪些错误。我的系统用mvc和cake构建php



"original_total_charged" being the id of the number string being returned.

Where is my issue? I feel that I understand what the issue is; but I don't know WHERE I've made my mistake. My system is built with mvc and cake php

推荐答案

500.00(我看到的)

总计:
500.00 (What I see)
Total:


5.00(我想要的)



以下是我在HTML文件中用来显示数据的代码片段。



5.00 (What I want)

Here is the snippet of code that I am using in my HTML file to show the data.

<?php echo ((isset(


processData [' original_total_charged'] )&&!empty(
processData['original_total_charged']) && !empty(


这篇关于如何将传入的JSON值转换为小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆