制作小数到分数转换器 [英] Making a decimal to fraction converter

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

问题描述

我正在制作一个程序,它将转换十进制输入(在这种情况下,在

英寸)并输出一个小数答案。目前,我只能通过三个部分输出分数答案:一个整数文本框,一个
分子文本框和一个分母文本框。我意识到这是

可能是最接近我会在VB中显示分数的,所以'

没什么大不了的。我能用我编写的一些代码来简化大多数数字,

但是我无法简化无限重复的任何事情(即1/3)。

有什么方法可以简化这个吗?


我可以给你一些我已经写过的代码,如果这样会有所帮助。 />

谢谢!

I''m making a program that will convert decimal inputs (in this case, in
inches) and output a fractional answer. At the moment, I''m only able to
output the fractional answer in three parts: A whole number text box, a
numerator text box, and a denominator text box. I realize that this is
probably the closest I''ll get to having fractions displayed in VB, so that''s
no big deal. I''m able to simplify most numbers with some code I''ve written,
but I''m unable to simplify anything that repeats infinitely (i.e.. 1/3). Is
there any way to be able to simplify this?

I can give you the code I''ve already written if that would help.

Thanks!

推荐答案

杰森,如果你可以让你的用户指定最好的毕业输出

(比如,64th,8th,quarters等),或者如果你假定某个最好的

毕业,你可以转换一个重复的分数然后舍入到

这个数字转换成最好的毕业,然后如果

可能减少它。


所以,例如,你的1 / 3是0.33333 ...如果你最好的毕业是128,

乘以0.33333 ...乘以128,得到42.66666 ...并且回合到43,给予

youi 43 / 128ths.


同样,1/9是0.11111 ...对于128ths,乘以0.11111 ...乘以128,得到

14.22222 ...圆到14 / 128ths并减少到7/64。

Tom Dacon

Dacon Software Consultin g


Jason < Ro *********** @ Quarters.com写了留言

新闻:20 ******************* *************** @ microsof t.com ...
Jason, if you can have your users specify the finest graduation to output
(say, 64ths, 8ths, quarters, etc.), or if you assume a certain finest
graduation, you can convert a repeating fraction and then round to the
finest graduation that the number converts to, and then reduce it if
possible.

So for instance, your 1/3 is 0.33333... If your finest graduation is 128ths,
multiply the 0.33333... by 128, getting 42.66666... and round to 43, giving
youi 43 / 128ths.

Similarly, 1/9 is 0.11111... For 128ths, multiply 0.11111... by 128, getting
14.22222... Round to 14/128ths and reduce to 7/64ths.
Tom Dacon
Dacon Software Consulting

"Jason" <Ro***********@Quarters.comwrote in message
news:20**********************************@microsof t.com...

我正在制作一个可以转换小数的程序输入(在这种情况下,在
英寸中)并输出一个小数答案。目前,我只能通过三个部分输出分数答案:一个整数文本框,一个
分子文本框和一个分母文本框。我意识到这是

可能是最接近我会在VB中显示分数的,所以

这没什么大不了的。我能用一些代码来简化大多数数字我已经写了,但是我无法简化无限重复的任何事情

(即1) / 3)。有什么方法可以简化这个吗?


我可以给你一些我已经写好的代码,如果那样会有所帮助。


谢谢!
I''m making a program that will convert decimal inputs (in this case, in
inches) and output a fractional answer. At the moment, I''m only able to
output the fractional answer in three parts: A whole number text box, a
numerator text box, and a denominator text box. I realize that this is
probably the closest I''ll get to having fractions displayed in VB, so
that''s no big deal. I''m able to simplify most numbers with some code I''ve
written, but I''m unable to simplify anything that repeats infinitely
(i.e.. 1/3). Is there any way to be able to simplify this?

I can give you the code I''ve already written if that would help.

Thanks!



该程序的目标是将小数转换为仅包含十进制数的

输入的分数,到目前为止,我只能简化

非重复十进制数。如果我让用户指定最好的

毕业,我需要一个截然不同的代码,而且我将超越

的目标program = \


如果没有指定最好的毕业,我的目标是否无望?


-Jason

" ;汤姆达肯 < td **** @ community.nospamwrote in message

news:ui ************** @ TK2MSFTNGP02.phx.gbl ...
The goal of the program is to convert decimals to fractions with only the
input of a decimal number, and thus far, I''ve only been able to simplify
nonrepeating decimal numbers. If I were to have the user specify the finest
graduation, I''d need a drastically different code, and I''d be going beyond
the goal of the program =\

Is my goal hopeless without specifying the finest graduation then?

-Jason
"Tom Dacon" <td****@community.nospamwrote in message
news:ui**************@TK2MSFTNGP02.phx.gbl...

Jason,如果你可以让你的用户指定最好的毕业作品输出

(比如说,64th,8th,quarter等),或者你假设某个最好的毕业,你可以转换一个重复的分数,然后四舍五入到数字转换为的最好的毕业,然后减少它,如果

可能。


例如,你的1/3是0.33333 ...如果你最好的毕业是

128ths,乘以0.33333 ...到128,获得42.66666 ...并且回合

43,给你43 / 128th。


同样,1/9是0.11111。 ..对于128ths,乘以0.11111 ...乘以128,

得到14.22222 ...回合到14 / 128ths并减少到7/64ths。


Tom Dacon

Dacon Software Consulting


Jason < Ro *********** @ Quarters.com写了留言

新闻:20 ******************* *************** @ microsof t.com ...
Jason, if you can have your users specify the finest graduation to output
(say, 64ths, 8ths, quarters, etc.), or if you assume a certain finest
graduation, you can convert a repeating fraction and then round to the
finest graduation that the number converts to, and then reduce it if
possible.

So for instance, your 1/3 is 0.33333... If your finest graduation is
128ths, multiply the 0.33333... by 128, getting 42.66666... and round to
43, giving youi 43 / 128ths.

Similarly, 1/9 is 0.11111... For 128ths, multiply 0.11111... by 128,
getting 14.22222... Round to 14/128ths and reduce to 7/64ths.
Tom Dacon
Dacon Software Consulting

"Jason" <Ro***********@Quarters.comwrote in message
news:20**********************************@microsof t.com...

>我正在创建一个程序转换十进制输入(在这种情况下,在
英寸)并输出一个小数答案。目前,我只能分三部分输出小数答案:一个整数文本框,一个
分子文本框和一个分母文本框。我意识到这可能是我在VB中显示分数最接近的,所以
这没什么大不了的。我能用一些代码简化大多数数字
我已经写过,但我无法简化无限重复的任何事情(即1/3)。有什么办法可以简化这个吗?

我可以给你一些我已经写过的代码,如果那样会有所帮助。

谢谢!
>I''m making a program that will convert decimal inputs (in this case, in
inches) and output a fractional answer. At the moment, I''m only able to
output the fractional answer in three parts: A whole number text box, a
numerator text box, and a denominator text box. I realize that this is
probably the closest I''ll get to having fractions displayed in VB, so
that''s no big deal. I''m able to simplify most numbers with some code
I''ve written, but I''m unable to simplify anything that repeats infinitely
(i.e.. 1/3). Is there any way to be able to simplify this?

I can give you the code I''ve already written if that would help.

Thanks!



首先,您可以将三个文本框中的结果显示为字符串:

text1.text& " " &安培; text2.text& " /" &安培; Text3.text


其次,任何重复的十进制数都可以用代码表示为正确的分数

,但你还没有表明你的问题是什么程序

是。


用户如何指示十进制数字无限重复

,或者是你的问题无法检测到什么时候重复

十进制?这可能是用正则表达式来解决的。


或者是你不知道如何减少常规重复

数的问题。分数?一旦你知道

特征,这就相对容易了。例如,如果它是一组简单的重复数字,

只需使用:


(重复是重复的位数,textbox1具有

要转换的数字)


s =拆分(TextBox1.Text,"。")

s(0)= s( 0)& s(1).Substring(0,重复)


numerator = Val(s(0)&"。"& s(1))


power = 10 ^重复


分子=分子 - 值


分母=功率 - 1


然后尽可能简化。如果它是一些独特的数字化后跟一个

重复部分,你需要在调整值时允许这样做,

然后调整分子和分母10的幂,直到你有
消除了分子的小数部分。


" Kasha" < Ro *********** @ Quarters.com写了留言

新闻:83 ******************* *************** @ microsof t.com ...
Firstly, you can present the results from the three text boxes as a string:
text1.text & " " & text2.text & "/" & Text3.text

Secondly, any repeating decimal can be represented as the correct fraction
using code, but you haven''t indicated what your problem with this procedure
is.

How is the user indicating that the decimal number is repeating
indefinately, or is the problem that you can''t detect when it''s a repeating
decimal? This could probably be solved with a regular expression.

Or is the problem that you don''t know how to reduce a regular repeating
number to a fraction? This is relatively easy, once you know the
characteristics. For instance, if its a simple set of repeating digits,
just use:

(Repeats is the number of digits that are repeated, textbox1 has the
number to convert)

s = Split(TextBox1.Text, ".")
s(0) = s(0) & s(1).Substring(0, repeats)

numerator = Val(s(0) & "." & s(1))

power = 10 ^ repeats

numerator = numerator - value

denominator = power - 1

then simplify if possible. If it''s some unique digitis followed by a
repeating portion you need to allow for that in the adjustment of the value,
and then adjust the numerator and denominator by powers of 10 until you have
eliminated the fractional part of the numerator.

"Kasha" <Ro***********@Quarters.comwrote in message
news:83**********************************@microsof t.com...

该程序的目标是将小数转换为分数只有一个十进制数的

输入,到目前为止,我只能简化

非重复十进制数。如果我要让用户指定

最好的毕业典礼,那么我需要一个完全不同的代码,而且我会去超过目标的
program = \


如果没有指定最好的毕业,我的目标是否无望?


-Jason

" ;汤姆达肯 < td **** @ community.nospamwrote in message

news:ui ************** @ TK2MSFTNGP02.phx.gbl ...
The goal of the program is to convert decimals to fractions with only the
input of a decimal number, and thus far, I''ve only been able to simplify
nonrepeating decimal numbers. If I were to have the user specify the
finest graduation, I''d need a drastically different code, and I''d be going
beyond the goal of the program =\

Is my goal hopeless without specifying the finest graduation then?

-Jason
"Tom Dacon" <td****@community.nospamwrote in message
news:ui**************@TK2MSFTNGP02.phx.gbl...

> Jason,如果你可以让你的用户指定最好的毕业作品输出
(比如说,64th,8th,quarters等),或者你假设一个最好的毕业,你可以转换一个重复的部分,然后圆形到数字转换为的最好的毕业,然后如果可能的话减少它。
例如,你的1/3是0.33333 ...如果你最好的毕业是第128位,将0.33333 ...乘以128,得到42.66666 ......并且转到
43,给你43 / 128ths.

类似地,1/9是0.11111 ...对于128ths,乘以0.11111 ...乘以128,得到14.22222 ...回合到14 / 128ths并减少到7/64th。

Tom Dacon
Dacon Software Consulting

Jason < Ro *********** @ Quarters.com写的消息
新闻:20 *********************** *********** @ microso ft.com ...
>Jason, if you can have your users specify the finest graduation to output
(say, 64ths, 8ths, quarters, etc.), or if you assume a certain finest
graduation, you can convert a repeating fraction and then round to the
finest graduation that the number converts to, and then reduce it if
possible.

So for instance, your 1/3 is 0.33333... If your finest graduation is
128ths, multiply the 0.33333... by 128, getting 42.66666... and round to
43, giving youi 43 / 128ths.

Similarly, 1/9 is 0.11111... For 128ths, multiply 0.11111... by 128,
getting 14.22222... Round to 14/128ths and reduce to 7/64ths.
Tom Dacon
Dacon Software Consulting

"Jason" <Ro***********@Quarters.comwrote in message
news:20**********************************@microso ft.com...

>>我正在制作一个可以转换小数的程序输入(在这种情况下,在
英寸)并输出一个分数答案。目前,我只能分三部分输出小数答案:一个整数文本框,一个
分子文本框和一个分母文本框。我意识到这可能是我在VB中显示分数最接近的,所以
这没什么大不了的。我能用一些代码简化大多数数字
我已经写过,但我无法简化无限重复的任何事情(即1/3)。有什么办法可以简化这个吗?

我可以给你一些我已经写过的代码,如果那样会有所帮助。

谢谢!
>>I''m making a program that will convert decimal inputs (in this case, in
inches) and output a fractional answer. At the moment, I''m only able to
output the fractional answer in three parts: A whole number text box, a
numerator text box, and a denominator text box. I realize that this is
probably the closest I''ll get to having fractions displayed in VB, so
that''s no big deal. I''m able to simplify most numbers with some code
I''ve written, but I''m unable to simplify anything that repeats
infinitely (i.e.. 1/3). Is there any way to be able to simplify this?

I can give you the code I''ve already written if that would help.

Thanks!



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

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