You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求百分比驱动的双区间数值转换数学公式

Solution for Dual-Range Value Conversion

Let's break down your requirements step by step and derive the exact mathematical formulas you need. First, let's restate your key parameters for clarity:

  • minNumber = 12
  • maxNumber = 24
  • maxLimit = 30
  • percentage ranges from 1.0 down to 0.0

First, Clarify the Conflict in Your Requirement

You mentioned two slightly conflicting points:

  1. When percentage drops from 1.0 to 0.5, the result should increase from minNumber (12) to maxLimit (30)
  2. When percentage = 1.0, result = 0

I'll provide solutions for both scenarios below, starting with the first (consistent with your primary dual-range logic).


Scenario 1: Follow the Dual-Range Increment/Decrement Logic (1.0 → 12, 0.5 →30, 0.0→24)

We split the formula into two conditional segments based on where percentage falls:

1. When percentage ≥ 0.5 (1.0 down to 0.5)

This maps the percentage range [1.0, 0.5] to the result range [12, 30]. The formula is:

result = 48 - 36 * percentage

Verification:

  • percentage = 1.0: 48 - 36*1 = 12 ✔️
  • percentage = 0.5: 48 - 36*0.5 = 30 ✔️

2. When percentage < 0.5 (0.5 down to 0.0)

This maps the percentage range [0.5, 0.0] to the result range [30, 24]. The formula is:

result = 24 + 12 * percentage

Verification:

  • percentage = 0.5: 24 + 12*0.5 = 30 ✔️
  • percentage = 0.0: 24 + 12*0 = 24 ✔️

If you need this as a single conditional expression (for code implementation), it would look like:

if percentage >= 0.5:
    result = 48 - 36 * percentage
else:
    result = 24 + 12 * percentage

Scenario 2: Honor the percentage=1.0 → result=0 Rule

If you strictly need result=0 when percentage=1.0 (even though it conflicts with the first range's stated starting point), adjust the first segment formula to:

1. When percentage ≥ 0.5

result = 60 * (1.0 - percentage)

Verification:

  • percentage=1.0: 60*(1-1)=0 ✔️
  • percentage=0.5: 60*(1-0.5)=30 ✔️

The second segment formula remains identical to Scenario 1.


How We Derived These Formulas

For linear mapping between two ranges, we use the standard linear interpolation framework:
result = start_value + (end_value - start_value) * normalized_percentage

  • For the first range, we normalized percentage to a 0-1 scale by calculating (1.0 - percentage)/0.5 (since the percentage spans 0.5 units from 1.0 to 0.5)
  • For the second range, we normalized with (0.5 - percentage)/0.5 to map 0.5→0 and 0.0→1, ensuring the result decreases from 30 to 24.

内容的提问来源于stack exchange,提问作者Scar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:44:30