有没有一种简单的方法可以将我的十进制值(例如62.25)转换为返回的字符串,例如“62小时:15分钟”?我一直在查看与此类似的几个帖子(Decimal Hour into Time?),但即使是那些说它们适用于超过24小时的数字的建议也无效。
答案 0 :(得分:4)
这很简单:
def listClients(request):
data = []
clientlist = clients.objects.filter(clientstatus=1)
#Here is where I don't know if I am doing correctly
#I don't know how to send the client list or if I have to send it as a JSON
#Please help here
data.append({'clist':clientlist })
return HttpResponse(json.dumps(data), content_type="application/json")

在c#中,您可能只是利用funtion getAllClients()
{
$.ajax(
{
type: "POST",
url: "/getAllClients/",
data: "",
success: function(result)
{
console.log(result); //Should I have a json object in 'result' variable?
$.each(result, function(key, val)
{
//Here is where I want to parse each object and add to the HTML table
});
}
});
}
类。见.NET fiddle here:
var decimal = 62.25;
var hours = Math.floor(decimal);
var mins = 60 * (decimal - hours);
console.log(`${hours} hours, ${mins} minutes`);
答案 1 :(得分:0)
这个问题非常简单,这个答案也很简单,并且有很多基本编程,并且有很多不同的方法。简单的一个是使用演员:
double date = getDate(); //62.25. I don't know where you get date from :P
int hours = (int)date; //62
float minutes = 60* (date - hours); //60 * (62.25 - 62 ) = 15
Write( "Hours: " + hours + "\nMinutes: " + minutes );
如果分钟有小数点(12.3分钟应该四舍五入等),请考虑进行条件化
答案 2 :(得分:0)
试试这个
Selection.TypeText ("ENTER")