mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 01:43:50 +01:00
30 lines
848 B
C#
30 lines
848 B
C#
using System;
|
|
|
|
namespace BTCPayServer.Rating
|
|
{
|
|
public static class Extensions
|
|
{
|
|
public static decimal RoundToSignificant(this decimal value, int divisibility)
|
|
{
|
|
return RoundToSignificant(value, ref divisibility);
|
|
}
|
|
public static decimal RoundToSignificant(this decimal value, ref int divisibility)
|
|
{
|
|
if (value != 0m)
|
|
{
|
|
while (true)
|
|
{
|
|
var rounded = decimal.Round(value, divisibility, MidpointRounding.AwayFromZero);
|
|
if ((Math.Abs(rounded - value) / value) < 0.01m)
|
|
{
|
|
value = rounded;
|
|
break;
|
|
}
|
|
divisibility++;
|
|
}
|
|
}
|
|
return value;
|
|
}
|
|
}
|
|
}
|