duanjing7651 2018-05-24 12:06 采纳率: 0%
浏览 224
已采纳

在Go中将小数赔率转换为分数(UK)赔率

I would have thought this was something a lot of people needed, but I can't seem to find any packages or repos/playground examples of anyone who has done it in Go.

The goal is to convert a string/float so that 1.20 (input) becomes 1/5 (output), 1.29 becomes 2/7, 2.38 becomes 11/8, etc.

  • 写回答

2条回答 默认 最新

  • doushan6692 2018-05-24 14:12
    关注

    From http://mybettingsites.co.uk/bet-calculator/odds-converter/#conversiontable

    How To Convert Decimal Odds To Fractional

    There are two steps to convert decimal odds into a fraction.

    Step 1) Convert decimals odds into a fraction by subtracting 1, and using 1 as the denominator.

    Example: 3.40 – 1 = 2.40. This creates the decimal odds of 2.40/1.

    While this is a perfectly good fraction, bookmakers never use numbers with decimal points in fractionals. That is why we need step two.

    Step 2) We now need to turn this fraction into its most simple form. Find the nearest whole integer (i.e. no decimal place). The factor to which you need to multiply the numerator to the whole integer is reflected in the denominator.

    Example: You need to multiply 2.40 by 5 before it becomes a rounded number, 12. Therefore the fraction becomes 12/5. (2.40 x 2 = 4.80, 2.40 x 3 = 7.20, 2.40 * 4 = 9.60, 2.40 * 5 = 12)

    The last step would be achieved by multiplying the top and bottom by 100 and dividing by the HCF / LCD. This can be found using my other answer, provided before you made it clear this was about betting, not general fractions

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含