Formatting scientific number representation in xsl

前端 未结 5 788
遇见更好的自我
遇见更好的自我 2020-12-03 19:45

I have the following value in my XML -1.8959581529998104E-4. I want to format this to the exact number it should be using XSL to give me -0.000189595815299981.

fo

5条回答
  •  情书的邮戳
    2020-12-03 20:37

    The logic doesn't appear to work correctly in the above answers by Moop and user357812 when determining vFactor in one particular scenario.

    If vExponent is a single-digit positive number (without a preceding '+' sign), then vFactor is set to an empty string. This is because an assumption was made that the 1st character of vExponent would be a plus/minus sign and therefore the 2nd character onwards were of interest. The vMantissa variable is then multiplied by an empty string which results in the template outputting NaN.

    If vExponent is a multi-digit positive number (without a preceding '+' sign), then vFactor is set to an incorrect value. Because of the aforementioned assumption, the 1st digit is ignored and the vMantissa is then multiplied by an incorrect vFactor.

    Therefore, I've modified the previously posted code a little so that it can handle scientific numbers of the forms: 2E-4, 2E+4 and 2E4.

    
        
        
        
        
        
        
            
                
            
            
                
            
                     
                
            
        
    
    

提交回复
热议问题