function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ckryzanckryzan 

Formulas: Raising a number to a power with a fractional exponent

We have some sophisticated math in our configuration/pricing system, which includes formulas in which (arbitrary) numbers need to be raised to (arbitrary) fractional powers. For example, a^2.3879 or b^6.912358. After debugging our pages when they simply didn't work (the formulas had to be set up as Workflow field updates), I determined (and then found an online reference to) the fact that Salesforce only allows positive, integer exponents.

 

Is there some way around this? I cannot imagine I'm the first person to encounter this issue. Some math library I could add to the system? Or workaround? Any advice is very much appreciated.

WizradWizrad

Well the work around is to change your math a little bit.

 

b^(-6.912358) = 1 / (b^6.912358)

sethgoosesethgoose

 


Wizrad wrote:

Well the work around is to change your math a little bit.

 

b^(-6.912358) = 1 / (b^6.912358)


"Salesforce only allows positive, integer exponents."

 

I agree. This should be standard salesforce functionality. A $5 calculator can handle fractional exponents.

MayTheForceBeWithYouMayTheForceBeWithYou

I actually do have a way to get around this until Salesforce provides native support. Although Salesforce currently only accepts positive, integer values as exponents the EXP function and LN function accept any number, including decimal values. Using a little math you can rearrange the problem-see the example below:

 

a = b^(c)

 

ln(a) = c * ln(b)

 

a = e ^ [ c * ln(b) ]

 

Rearranging the problem into this format allows you to utilize the EXP and LN functions, which as mentioned before, can accept decimals and negative values alike.

Frank Chang 13Frank Chang 13
@MayTheForceBeWithYou - Awesome solution.  Like most people, I've forgotten most of what I learned from Algebra and Trigonometry 
Kiran Chowhan 13Kiran Chowhan 13
Example:
Adjusted Quantity formula field on Quote Line object where my exponent is 0.59 and I want to use an adjusted quantity which will be used to calculate Net Price.

Fail:
Adjusted Quantity (Number) =
SBQQ__Quantity__c ^ 0.59

Success:
Adjusted Quantity (Number) =
EXP(0.59 * LN( SBQQ__Quantity__c ))