Approved: Fortect
Over the past few days, some of our users have reported xslt rounding errors.
We are facing a very strange crisis with XSLT rounding and number formatting. Let’s say I have a number like 131 855 and I want to round it to two or three decimal places. I expect 131.86 as an option, but the xslt Round () function rounds it to 131.85. I have tried usingUse “round (131.855 * 100) div 100” to make it not work. On the other hand, if I need to round a phone number like 127.855, the same code will round it from 127 to 86, that is, “round (127.855 * 100) div 100”. rounded up to 131.76 !! Very strange.We may have tried using format-number (), but the function that actually gives strange results. For example, I take the number 349615.225 I and take the format number on it, that is, the format number (349615.225, ‘#. ##’) activates 349615.22, and I am waiting for decimal fractions 0.25. But if I use a format number around 131.855 it converts to 131.86 …
I’ve also tried using round () over and over again inside work format-number (), but it gave the most extreme results.
We are using XSLT 1.0. Moving to XSLT 2.0 seems like a daunting task. The workaround costs nothing, but I can see that I am using the cappuccino function and calling it from XSL to complete.
asked Oct 23 15 going at 4:57
Not The Answer You Are Looking For? Review All Other Questions Marked With Xml Xslt Xslt-1.0 Rounding And Ask Your Own Question.
The round ()
function rounds a given number to the nearest integer, and the actual use of round ()
may not round our own number correctly. format-number ()
formats data with selections, which truncate the data (presumably), which can lead to loss of value.
Using each type of round ()
and format-number ()
should work efficiently.
5.225
* Select = "format-number (round (100
answered Oct 15 I’m at 5:40 am.
5.297
The most surprising thing to understand is that when a person writes a number like 131,855, the measurable value it represents is not perfectly between 131.85 and 131.86. There probably won’t be a double precision floating point number that is numerically 131 855, so the real value of the person you control will be lower or slightly higher. This inaccuracy occurs immediately after you write down the number, not just when you rely on it. If your organization multiplies it by 100, that difference will increase, and if you use round (), it will jump to the nearest integer, which sometimes depends on whether the approximation is increasing or decreasing. Since XSLT 1.0 only contains floating point numbers, there is no workaround for this type of problem.
Approved: Fortect
Fortect is the world's most popular and effective PC repair tool. It is trusted by millions of people to keep their systems running fast, smooth, and error-free. With its simple user interface and powerful scanning engine, Fortect quickly finds and fixes a broad range of Windows problems - from system instability and security issues to memory management and performance bottlenecks.
Ten can be used in XSLT 2.0 Numbers in everyday life. more than people expect.
answered Oct 15 at 8:23 am.
141k
Speed up your computer's performance now with this simple download.