欢迎光临
我们一直在努力

函数小数转分数,限于整除分数

建站超值云服务器,限时71元/月

函数实现小数转分数

public function xtof(str as currency, optional fenm as integer = 32) as string 只限于整除分数

dim cfm as currency

dim cfmmod as integer

on error goto erroreof

cfm = 1 / fenm

xtof = ""

if str = 0 then xtof = "": exit function

dim point as integer

dim dint as string

dim dpoint as currency

dim fint, fint1, fint2 as integer

if str <> 0 then

if str > 1 then

point = instr(1, str, ".", 1)

if point = 0 then

xtof = str:

exit function

else

dint = mid(str, 1, point – 1)

dpoint = ccur("0." & mid(str, point + 1))

fint = instr(1, xtof(dpoint), "/", 1)

fint1 = cint(mid(xtof(dpoint), 1, fint – 1))

fint2 = cint(mid(xtof(dpoint), fint + 1))

xtof = cstr(dint * fint2 + fint1) & "/" & cstr(fint2)

end if

else

if fenm mod cint(str / cfm) = 0 then

xtof = "1/" + cstr(fenm / cint(str / cfm))

else

cfmmod = maxgys(fenm, cint(str / cfm))

xtof = cstr(cint(str / cfm / cfmmod)) + "/" + cstr(cint(fenm / cfmmod))

end if

end if

else

xtof = "0"

end if

exit function

erroreof:

xtof = ""

end function

function maxgys(num1 as integer, num2 as integer) as integer

dim minnum, i as integer

minnum = num1

if num1 > num2 then minnum = num2

for i = 1 to minnum

if ((num1 mod i) = 0) and ((num2 mod i) = 0) then maxgys = i

next i

end function

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 函数小数转分数,限于整除分数
分享到: 更多 (0)