add Percent % to Units
This commit is contained in:
parent
f1003c2877
commit
9bf23f3ec8
|
@ -0,0 +1,29 @@
|
||||||
|
namespace InnovEnergy.Lib.Units;
|
||||||
|
|
||||||
|
using T = Percent;
|
||||||
|
|
||||||
|
public readonly struct Percent
|
||||||
|
{
|
||||||
|
public static String Unit => "%";
|
||||||
|
public static String Symbol => "%"; // ??
|
||||||
|
|
||||||
|
public Percent(Decimal value)
|
||||||
|
{
|
||||||
|
if (value < 0)
|
||||||
|
throw new ArgumentException(nameof(Frequency) + " cannot be negative", nameof(value));
|
||||||
|
|
||||||
|
Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// not generated
|
||||||
|
|
||||||
|
public Decimal Value { get; }
|
||||||
|
public override String ToString() => Value + Unit;
|
||||||
|
|
||||||
|
// scalar multiplication
|
||||||
|
public static Decimal operator *(Decimal scalar, T t) => scalar * t.Value/100m;
|
||||||
|
public static Decimal operator *(T t, Decimal scalar) => scalar * t.Value/100m;
|
||||||
|
|
||||||
|
// parallel
|
||||||
|
public static Percent operator |(T left, T right) => new T((left.Value + right.Value)/2m);
|
||||||
|
}
|
Loading…
Reference in New Issue