You can do this with an extension method (e.g. for decimal ):
public static class ExtensionMethods { public static decimal Map (this decimal value, decimal fromSource, decimal toSource, decimal fromTarget, decimal toTarget) { return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget; } }
Then you can use it like:
decimal res = 2.Map(1, 3, 0, 10);
Yannick blondeau
source share