[WebApi]修改Niagara撈的資料有科學記號問題,並抓到小數點第2位

This commit is contained in:
張家睿 2024-05-07 18:07:05 +08:00
parent 7c3e699a79
commit f49d2a749f

View File

@ -281,7 +281,13 @@ namespace FrontendWebApi.Models
}
public class HistoryBuildingDevice
{
public string building_tag { get; set; }
private string _building_tag;
public string building_tag
{
get { return _building_tag; }
set { _building_tag = value.Replace("$3", ""); }
}
public string building_name { get; set; }
public List<HistoryDevice> device_list { get; set; }
@ -360,14 +366,30 @@ namespace FrontendWebApi.Models
public class HistoryRawData : DeviceItemInfo
{
public string Value { get; set; }
private string _Value;
public string Value
{
get { return _Value; }
set
{
_Value = StringHelper.TruncateDecimal(value);
}
}
public string Timestamp { get; set; }
}
public class HistoryExport
{
private string _value;
public string deviceName { get; set; }
public string value { get; set; }
public string value
{
get { return _value; }
set
{
_value = StringHelper.TruncateDecimal(value);
}
}
public DateTime timestamp { get; set; }
public DateTime starttime { get; set; }
public DateTime? endtime { get; set; }
@ -376,6 +398,22 @@ namespace FrontendWebApi.Models
public string building_tag { get; set; }
public string device_number { get; set; }
}
public static class StringHelper
{
// 截取小數點後兩位數字
public static string TruncateDecimal(string input)
{
// 如果是科學記號先做解析,再截取
if (double.TryParse(input, out double number))
{
return number.ToString("F2");
}
else
{
return string.Empty;
}
}
}
public class History_Building
{
@ -386,9 +424,14 @@ namespace FrontendWebApi.Models
public class DeviceNumberPoint
{
private string _FullDeviceNumberPoint;
public string DeviceNumber { get; set; }
public string Point { get; set; }
public string FullDeviceNumberPoint { get; set; }
public string FullDeviceNumberPoint
{
get { return _FullDeviceNumberPoint; }
set { _FullDeviceNumberPoint = value.Replace("$3", ""); }
}
}
public class BuildStation