我的小数值为123.77
现在我想使用MySQL将其转换为相应的degree
,minute
,second
值。
我尝试了几种方法,但无法得到正确的答案。请帮忙。
答案 0 :(得分:1)
这是怎么回事,
查询,
SET @deci = 123.77;
SELECT FLOOR(@deci) Degrees,
FLOOR((@deci - (FLOOR(@deci))) * 60) Minutes,
((@deci - (FLOOR(@deci))) * 60 -
FLOOR((@deci - (FLOOR(@deci))) * 60)) * 60 SECONDS
<强> Online Conversion Tool (for checking) 强>
答案 1 :(得分:0)
John Woo给出的答案虽然正值正确,但不能给出负值的正确结果。我已经调整了他的答案以考虑到这一点。
SET @deci = -123.77;
SELECT SIGN(@deci)* FLOOR(ABS(@deci)) Degrees,
FLOOR((ABS(@deci) - (FLOOR(ABS(@deci)))) * 60) Minutes,
((ABS(@deci) - (FLOOR(ABS(@deci)))) * 60 -
FLOOR((ABS(@deci) - (FLOOR(ABS(@deci)))) * 60)) * 60 SECONDS
答案 2 :(得分:0)
开箱即用,借用不同的基于巴比伦语的指标:
Uncaught TypeError: Cannot read property 'appendChild' of null
at window.(anonymous function)._insertRowAt (http://localhost:8080/QMTM_DEMO/dhtmlxGrid/codebase/dhtmlxgrid.js:725:65)
at window.(anonymous function).render_dataset (http://localhost:8080/QMTM_DEMO/dhtmlxGrid/codebase/dhtmlxgrid.js:671:197)
at window.(anonymous function)._process_json (http://localhost:8080/QMTM_DEMO/dhtmlxGrid/codebase/dhtmlxgrid.js:665:36)
at window.(anonymous function).parse (http://localhost:8080/QMTM_DEMO/dhtmlxGrid/codebase/dhtmlxgrid.js:617:178)
at qlist1_reload(http://localhost:8080/project/tmanager/exam/make_write.jsp?id_exam=E170907095612NA:72:15)
at http://localhost:8080/QMTM_project/tmanager/exam/q_search_ok.jsp:25:9
(mysql> SELECT TIME_FORMAT("%H°%i'%s", SEC_TO_TIME(ROUND(3600 * -1.234)));
+-------------------------------------------------------------+
| TIME_FORMAT("%H°%i'%s", SEC_TO_TIME(ROUND(3600 * -1.234))) |
+-------------------------------------------------------------+
| -01:14:02 |
+-------------------------------------------------------------+
mysql> SELECT TIME_FORMAT("%H°%i'%s", SEC_TO_TIME(ROUND(3600 * -123.77)));
+--------------------------------------------------------------+
| TIME_FORMAT("%H°%i'%s", SEC_TO_TIME(ROUND(3600 * -123.77))) |
+--------------------------------------------------------------+
| -123:46:12 |
+--------------------------------------------------------------+
是为了避免在答案中得到3个小数位。)