Open oeb25 opened 8 years ago
Hi @oeb25,
As far as I can tell, there is an ambiguity problem with implementing your requested feature (see https://github.com/Keno/SIUnits.jl/pull/54).
In case you have not had a chance to work it out by now, the following code shows how you can implement your own "pretty" function, while you wait for things to get sorted out:
using SIUnits
using SIUnits.ShortUnits
typealias _Volts{T} SIUnits.SIQuantity{T,2,1,-3,-1,0,0,0,0,0}
typealias _Watts{T} SIUnits.SIQuantity{T,2,1,-3,0,0,0,0,0,0}
pretty(x::_Volts) = "$(x.val)V"
pretty(x::_Watts) = "$(x.val)W"
Comments
typeof(4*W)
# Shows "W" type => SIUnits.SIQuantity{Int64,2,1,-3,0,0,0,0,0,0}
When printing or converting values with assigned units the output is close to humanly unreadable.
Examples
If a
toString
metod like the one in javascript for auto pretty printing on the units isn't posible in Julia, a function like the one below would be just fineI know zero to none about Julia, I only use it to calcualte math and physics, so I can unfortunately not implement this myself