# ANN: RoundingIntegers.jl

**URL:** <https://discourse.julialang.org/t/ann-roundingintegers-jl/2820>\
**Category:** Community\
**Tags:** package, numbers\
**Created:** [March 22, 2017, 4:53pm UTC](https://discourse.julialang.org/t/ann-roundingintegers-jl/2820 "2017-03-22T16:53:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [March 22, 2017, 4:53pm UTC](https://discourse.julialang.org/t/ann-roundingintegers-jl/2820/1 "2017-03-22T16:53:59Z")

</div>

I’d like to announce the [RoundingIntegers](https://github.com/JuliaMath/RoundingIntegers.jl), a tiny package that adds new `Integer` types. Very simply, `RoundingInteger`s always round when you assign to them. For example:

```julia
julia> Int(7.2) # fails with "regular" integers
ERROR: InexactError()
 in Int64(::Float64) at ./sysimg.jl:53

julia> RInt(7.2) # but not with a rounding integer
7

```

I suspect their main usage is in containers, e.g., `Vector{RInt}` would allow you to assign floating-point values that then automatically get rounded. My motivation for adding this was that I had written specialized logic for this kind of operation:

```julia
safe_setindex!{T<:Integer}(a::AbstractArray{T}, x::Real, inds...) = a[inds...] = round(T, x)
safe_setindex!(a::AbstractArray, x::Real, inds...) = a[inds...] = x

```

one too many times. It just seems cleaner to encode it in the type (it lets the user decided whether s/he wants an error or no error for this kind of operation).
