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 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!