Number format not working correctly
Posted: 27 Feb 2017 04:48
So I am using a battery widget someone shared here. I have made a few modifications so I could get the widget on my smart watch too, and the battery life didn't work correct, so I swapped it to voltage all the time. The issue I am having is that I wanted to convert the temperature from Celsius to Fahrenheit. Here are the instructions for the operations.
global_battery_level=battery_level;
global_battery_health=battery_health;
global_battery_percentage=battery_percentage;
global_battery_plugged=battery_plugged;
global_battery_present=battery_present;
global_battery_scale=battery_scale;
global_battery_status_text = "";
if (battery_status == 4){
global_battery_status_text = "discharging";
}
if (battery_status == 2) {
global_battery_status_text = "charging";
}
if (battery_status == 5) {
global_battery_status_text = "full";
}
global_battery_technology=battery_technology;
global_battery_voltage=battery_voltage;
global_battery_temperature="{battery_temperature*1.8+32,numberformat,0.00}";
global_battery_temperature=global_battery_temperature/10;
global_battCurrentTime = getDate();
global_battTimeRemain = 0;
battDiff = global_battChargedLevel - global_battery_level - 5;
battTimeDiff = global_battCurrentTime - global_battChargedTime;
if (battDiff > 0){
if (battTimeDiff > 0) {
global_battTimeRemain = global_battery_level * (battTimeDiff / battDiff);
global_battRemainText = "{global_battTimeRemain, dateformat, kk}h {global_battTimeRemain, dateformat, mm}m";
}}
if (global_battTimeRemain > 86400000){
days = global_battTimeRemain / 86400000;
global_battRemainText = "{days}d+";
}
And
//Force update of widget text items
setWidgetElementProperty("BatteryBDIV1", "Level", "text", "{global_battery_level}%");
setWidgetElementProperty("BatteryBDIV1", "STATUS", "text", "{global_battery_status_text}");
setWidgetElementProperty("BatteryBDIV1", "Voltage", "text", "{global_battery_voltage}mV");
setWidgetElementProperty("BatteryBDIV1", "Temp", "text", "{global_battery_temperature}°F");
setWidgetElementProperty("BatteryBDIV1", "Ellipse_fill", "outlinecolor", "#ff00ff00");
arcind = 3.6*global_battery_level;
setWidgetElementProperty("BatteryBDIV1", "Ellipse_fill", "sweepangle", arcind);
/*if (global_battTimeRemain > 0) {
setWidgetElementProperty("BatteryBDIV1", "Voltage", "text", "{global_battRemainText}");
}
else {
setWidgetElementProperty("BatteryBDIV1", "Voltage", "text", "...");
} */
The problem is even with the number format in there the widget will show an extended value part the decimal point.
Thanks
global_battery_level=battery_level;
global_battery_health=battery_health;
global_battery_percentage=battery_percentage;
global_battery_plugged=battery_plugged;
global_battery_present=battery_present;
global_battery_scale=battery_scale;
global_battery_status_text = "";
if (battery_status == 4){
global_battery_status_text = "discharging";
}
if (battery_status == 2) {
global_battery_status_text = "charging";
}
if (battery_status == 5) {
global_battery_status_text = "full";
}
global_battery_technology=battery_technology;
global_battery_voltage=battery_voltage;
global_battery_temperature="{battery_temperature*1.8+32,numberformat,0.00}";
global_battery_temperature=global_battery_temperature/10;
global_battCurrentTime = getDate();
global_battTimeRemain = 0;
battDiff = global_battChargedLevel - global_battery_level - 5;
battTimeDiff = global_battCurrentTime - global_battChargedTime;
if (battDiff > 0){
if (battTimeDiff > 0) {
global_battTimeRemain = global_battery_level * (battTimeDiff / battDiff);
global_battRemainText = "{global_battTimeRemain, dateformat, kk}h {global_battTimeRemain, dateformat, mm}m";
}}
if (global_battTimeRemain > 86400000){
days = global_battTimeRemain / 86400000;
global_battRemainText = "{days}d+";
}
And
//Force update of widget text items
setWidgetElementProperty("BatteryBDIV1", "Level", "text", "{global_battery_level}%");
setWidgetElementProperty("BatteryBDIV1", "STATUS", "text", "{global_battery_status_text}");
setWidgetElementProperty("BatteryBDIV1", "Voltage", "text", "{global_battery_voltage}mV");
setWidgetElementProperty("BatteryBDIV1", "Temp", "text", "{global_battery_temperature}°F");
setWidgetElementProperty("BatteryBDIV1", "Ellipse_fill", "outlinecolor", "#ff00ff00");
arcind = 3.6*global_battery_level;
setWidgetElementProperty("BatteryBDIV1", "Ellipse_fill", "sweepangle", arcind);
/*if (global_battTimeRemain > 0) {
setWidgetElementProperty("BatteryBDIV1", "Voltage", "text", "{global_battRemainText}");
}
else {
setWidgetElementProperty("BatteryBDIV1", "Voltage", "text", "...");
} */
The problem is even with the number format in there the widget will show an extended value part the decimal point.
Thanks