从分数为十进制和后退? [英] From Fraction to Decimal and Back?

查看:149
本文介绍了从分数为十进制和后退?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能像3/6的一小部分存储在某种类型的变量?
当我尝试这一点,只/前存储的数字。我知道,我可以使用2个变量和他们分开,但输入的是从单一的文本字段。这是在所有可能的?

Is it possible to store a fraction like 3/6 in a variable of some sort? When I try this it only stores the numbers before the /. I know that I can use 2 variables and divide them, but the input is from a single text field. Is this at all possible?

我想这样做,因为我需要计算的部分,小数赔率。

I want to do this because I need to calculate the fractions to decimal odds.

奖金问题) - 有一种简单的方法来计算一个十进制值的一小部分?谢谢..

A bonus question ;) - Is there an easy way to calculate a decimal value to a fraction? Thanks..

推荐答案

做的最好的事情就是实现一个分数级(或有理数类)。通常它会采取一个分子和分母,并能够提供一个双,并做基本的数学与其他部分的对象。它也应当能够分析和格式化馏分

The best thing to do is to implement a fraction class (or rational number class). Normally it would take a numerator and denominator and be able to provide a double, and do basic math with other fraction objects. It should also be able to parse and format fractions.

上罗塞塔code 理性算术看起来像是不错的开始。

Rational Arithmetic on Rosetta Code looks like something good to start with.

这篇关于从分数为十进制和后退?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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