我正在使用 eclipse 创建一个 Android 应用程序,它将读取用户输入的价格。
输入的价格应存储到数据库(phpmyadmin)
我正在使用下面的代码,但 Eclipse 出错并要求我将 double 转换为字符串。
food = Double.parseDouble(inputFood.getText().toString());
transport = Double.parseDouble(inputTransport.getText().toString());
tele = Double.parseDouble(inputTele.getText().toString());
academic = Double.parseDouble(inputAcademic.getText().toString());
entertainment = Double.parseDouble(inputEntertainment.getText().toString());
health = Double.parseDouble(inputHealth.getText().toString());
others = Double.parseDouble(inputOthers.getText().toString());
budget = Double.parseDouble(inputBudget.getText().toString());
total = food + transport + tele + academic + entertainment + health + others;
balance = budget - total;
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("food", food));
params.add(new BasicNameValuePair("transport", transport));
params.add(new BasicNameValuePair("tele", tele));
params.add(new BasicNameValuePair("academic", academic));
params.add(new BasicNameValuePair("entertainment", entertainment));
params.add(new BasicNameValuePair("health", health));
params.add(new BasicNameValuePair("others", others));
params.add(new BasicNameValuePair("budget", budget));
params.add(new BasicNameValuePair("total", total));
params.add(new BasicNameValuePair("balance", balance));
JSONObject json = jsonParser.makeHttpRequest(url_save_expenses,
"GET", params);
是否还有其他编码用于存储 double 据?
感谢您的回答..
最佳答案
只需编写代码以这种方式在列表中添加参数
params.add(new BasicNameValuePair("food", "" + food));
params.add(new BasicNameValuePair("transport", "" + transport));
params.add(new BasicNameValuePair("tele", "" + tele));
params.add(new BasicNameValuePair("academic", "" + academic));
params.add(new BasicNameValuePair("entertainment", "" + entertainment));
params.add(new BasicNameValuePair("health", "" + health));
params.add(new BasicNameValuePair("others", "" + others));
params.add(new BasicNameValuePair("budget", "" + budget));
params.add(new BasicNameValuePair("total", "" + total));
params.add(new BasicNameValuePair("balance", "" + balance));
这将将此构造函数的 double 类型更改为字符串,并在服务器端将字符串转换为 double 并存储到数据库中
关于java - 如何将Double类型的数据插入phpmyadmin?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13777036/