另一种范围内的范围内,数字转换为数字 [英] Convert numbers within a range to numbers within another range

查看:284
本文介绍了另一种范围内的范围内,数字转换为数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
转换数字范围到另一范围,保持比

所以我有在0和255返回值的函数,我需要将这些值转换的东西之间-255和255
所以200将大致145,150将是大约45等..
我已经看过外汇牌价编号范围到另一个范围,保持比但是计算公式也将无法正常工作。
任何其他公式,我可以使用

So I have a function that returns values within 0 and 255 and I need to convert these values to something between -255 and 255 So 200 would be roughly 145, 150 would be roughly 45 and so on.. I have looked at Convert a number range to another range, maintaining ratio but the formulas there won't work. Any other formula I could use?

推荐答案

试试这个:

int Adjust( int num )
{
    return num * 2 - 255;
}

这篇关于另一种范围内的范围内,数字转换为数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆