{"action":"created","issue":{"url":"https://api.github.com/repos/shopspring/decimal/issues/95","repository_url":"https://api.github.com/repos/shopspring/decimal","labels_url":"https://api.github.com/repos/shopspring/decimal/issues/95/labels{/name}","comments_url":"https://api.github.com/repos/shopspring/decimal/issues/95/comments","events_url":"https://api.github.com/repos/shopspring/decimal/issues/95/events","html_url":"https://github.com/shopspring/decimal/issues/95","id":330238278,"node_id":"MDU6SXNzdWUzMzAyMzgyNzg=","number":95,"title":"Inconsistent behaviour for different types of input values","user":{"login":"breathbath","id":7046326,"node_id":"MDQ6VXNlcjcwNDYzMjY=","avatar_url":"https://avatars1.githubusercontent.com/u/7046326?v=4","gravatar_id":"","url":"https://api.github.com/users/breathbath","html_url":"https://github.com/breathbath","followers_url":"https://api.github.com/users/breathbath/followers","following_url":"https://api.github.com/users/breathbath/following{/other_user}","gists_url":"https://api.github.com/users/breathbath/gists{/gist_id}","starred_url":"https://api.github.com/users/breathbath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/breathbath/subscriptions","organizations_url":"https://api.github.com/users/breathbath/orgs","repos_url":"https://api.github.com/users/breathbath/repos","events_url":"https://api.github.com/users/breathbath/events{/privacy}","received_events_url":"https://api.github.com/users/breathbath/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-06-07T11:51:45Z","updated_at":"2018-06-07T21:33:00Z","closed_at":null,"author_association":"NONE","body":"`decimal.NewFromFloat(0.357).Div(decimal.NewFromFloat(0.001)).Floor()`\r\n\r\ngives 356 \r\nand\r\n```\r\nx,_ := decimal.NewFromString(\"0.357\")\r\ny,_ := decimal.NewFromString(\"0.001\")\r\nx.Div(y).Floor()\r\n```\r\n\r\ngives 357\r\nbut the result should be consistent imho"},"comment":{"url":"https://api.github.com/repos/shopspring/decimal/issues/comments/395572259","html_url":"https://github.com/shopspring/decimal/issues/95#issuecomment-395572259","issue_url":"https://api.github.com/repos/shopspring/decimal/issues/95","id":395572259,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NTU3MjI1OQ==","user":{"login":"peterstace","id":5352655,"node_id":"MDQ6VXNlcjUzNTI2NTU=","avatar_url":"https://avatars1.githubusercontent.com/u/5352655?v=4","gravatar_id":"","url":"https://api.github.com/users/peterstace","html_url":"https://github.com/peterstace","followers_url":"https://api.github.com/users/peterstace/followers","following_url":"https://api.github.com/users/peterstace/following{/other_user}","gists_url":"https://api.github.com/users/peterstace/gists{/gist_id}","starred_url":"https://api.github.com/users/peterstace/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterstace/subscriptions","organizations_url":"https://api.github.com/users/peterstace/orgs","repos_url":"https://api.github.com/users/peterstace/repos","events_url":"https://api.github.com/users/peterstace/events{/privacy}","received_events_url":"https://api.github.com/users/peterstace/received_events","type":"User","site_admin":false},"created_at":"2018-06-07T21:33:00Z","updated_at":"2018-06-07T21:33:00Z","author_association":"NONE","body":"I don't think it's really a problem with the library, it's just a consequence of how IEEE floats work. When you write the `float64` literal `0.357`, it doesn't represent the mathematical number 0.357. That number cannot be represented accurately using a float64 since it's not the sum of powers of 2. Instead, it represents (exactly) the number 0.3569999999999999840127884453977458178997039794921875\r\n\r\nYou can use the stringconv package to show the exact number represented by a particular float64. E.g.:\r\n\r\n```\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"strconv\"\r\n)\r\n\r\nfunc main() {\r\n\tvar x float64 = 0.357\r\n\tfmt.Printf(strconv.FormatFloat(x, 'f', 100, 64))\r\n}\r\n```\r\ngives output: `0.3569999999999999840127884453977458178997039794921875000000000000000000000000000000000000000000000000`\r\n\r\nNewFromFloat is creating a Decimal object precisely equal to the inputted float64."}}
{"actor":{"display_login":"peterstace"}}