将分数转换为小数 [英] Convert fraction to decimal

查看:95
本文介绍了将分数转换为小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

研究10g.

我正在编写查询以对列表进行排序,而排序是列表的重要方面.

I am writing a query to sort a list, and sorting is an important aspect of the list.

我已经从分数中分离出分数了.

I have already isolated the fraction from the mixed number.

我有分数形式的数据. (3/4,5/8,1/2)

I have data that come in fraction form. (3/4, 5/8, 1/2)

我需要将它们转换为十进制,以便能够对其进行排序".

I need to convert them to decimal to be able to 'order by' with them.

任何帮助将不胜感激.

推荐答案

如果输入不是 分数(例如3/4、5/8等),则会严重炸毁去了:

This will blow up badly if the input is not a fraction such as 3/4, 5/8, etc., but here goes:

CAST(SUBSTR(theFraction, 1, INSTR(theFraction, '/')-1) AS NUMBER) /
CAST(SUBSTR(theFraction, INSTR(theFraction, '/')+1) AS NUMBER)

逻辑基本上是将'/'之前的所有内容转换为数字,然后将'/'之后的所有内容除以数字".

The logic is basically "get everything before the '/' and convert it to a number, then divide it by everything after the '/' converted as a number".

这篇关于将分数转换为小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆