Guest User

Untitled

a guest
Mar 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. c1 = Decimal.div(a1, b1)
  2. # => #Decimal<0.006453859622556080696687234694>
  3.  
  4. iex> alias Decimal, as: D
  5. nil
  6. iex> d = D.div(D.new(1), D.new(3))
  7. #Decimal<0.3333333333333333333333333333>
  8. iex> D.round(d, 5)
  9. #Decimal<0.33333>
  10.  
  11. iex> D.set_context(%D.Context{D.get_context | precision: 5})
  12. :ok
  13. iex> a = D.div(D.new(100.12345), D.new(3))
  14. #Decimal<33.374>
  15.  
  16. iex> D.set_context(%D.Context{D.get_context | precision: 5})
  17. :ok
  18. iex> a = D.div(D.new(1), D.new(3))
  19. #Decimal<0.33333>
  20. iex> b = D.new("0.006453859622556080696687234694")
  21. #Decimal<0.006453859622556080696687234694>
  22. iex> D.add(a,b)
  23. #Decimal<0.33978>
  24.  
  25. rounded_c1 = Decimal.round(c1, 4)
  26.  
  27. ceil_c1 = Decimal.round(c1, 4, :ceiling)
  28. floor_c1 = Decimal.round(c1, 4, :floor)
Add Comment
Please, Sign In to add comment