You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 fine
# SIUnit -> Stringpretty(5V *2A)
# => 10W
I know zero to none about Julia, I only use it to calcualte math and physics, so I can unfortunately not implement this myself
The text was updated successfully, but these errors were encountered:
As far as I can tell, there is an ambiguity problem with implementing your requested feature
(see #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
The _Volts & _Watts typealias-es are defined simply for convenience/readability.... and underscores were added to avoid collisions with other symbols out there.
To figure out what "SIQuantity" you need for a unit, run the following (replace with unit of interest):
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
The text was updated successfully, but these errors were encountered: