Replies: 4 comments 1 reply
-
Hi, for dimensionless we suggest using Ratio. As you say, you don't get to represent the actual unit abbreviations this way. You could absolutely create your own custom quantity, see https://github.com/angularsen/UnitsNet/wiki/Extending-with-Custom-Units. Note that the wiki examples are a bit outdated related to Not sure if relevant, but there is also some notes on serialization here, but nothing specifically for custom quantities: |
Beta Was this translation helpful? Give feedback.
-
This is not the first time someone requests a particular dimensionless unit. I'm not sure what your needs are, but could you just create a simple wrapper type that holds the unit abbreviations? Something like: public struct HeatRate(Ratio Value, string Abbreviation) // "kJ/kWh" or "BTU/kWh"
{
public override string ToString() => $"{Value.DecimalFractions} {Abbreviation}";
} |
Beta Was this translation helpful? Give feedback.
-
Hi, thanks for your answers. |
Beta Was this translation helpful? Give feedback.
-
I see, I suppose it would be possible to extend https://github.com/angularsen/UnitsNet/wiki/Serializing-to-JSON,-XML-and-more If we could find a generic way to support any dimensionless unit, then that would be interesting to add to UnitsNet. Is this something you would be willing to attempt a pull request on? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
we are using this nuget package in our solutions and it`s great so far.
In the context of power plants there is a thing called heat rate (see wiki). It's a ratio of thermal energy in vs electrical energy out (efficiency) and is therefore dimensionless, but mostly expressed by energy/energy like kJ/kWh or BTU/kWh.
We are saving the name of the quantity and the name of the unit together with the value in our database. What is the best approach I can take to store kJ/kWh since it doesn't exist but is needed in that format? Should I create a new unit definition?
Tanks in advance for your input!
Beta Was this translation helpful? Give feedback.
All reactions