Javascript how to make a number from a string. How is a string converted to a number in javascript? Transformation for sorting

JavaScript is a language with dynamic data typing. This means that you can write values ​​to the same variable various types, while the type of the variable itself will change. This behavior often makes it possible to forget about the different behavior of variables with different type, but it is still necessary to remember this feature. Let's show this in the following example.

console.log(sum(1, 2)); // 3 (everything is ok here) console.log(sum(1, "2")); // 12 (and not so much here)

As you can see from the example, the function sum behaves incorrectly if at least one of its arguments is not a number. The fact is that when “adding” a number to a string, the number is converted to a string and it is concatenated (glued) with the second operand.

To avoid such complications, you can find out the type of a variable during script execution and correct its behavior, or carefully monitor the types of variables.

typeof operator

This unary operator takes absolutely any value as an operand and returns its type in a string variable.

JavaScript has the following types data:

// 1.) object console. log (typeof ( ) ) ; // object var p = ( x: 1 , y: 3 ) ; console. log (typeof p) ; // object // 2.) function function sayHello() ( console.log ("Hello!" ) ; ) console.log (typeof sayHello) ; // function // 3.) string console.log (typeof "JavaScript" ) ; // string // 4.) number console.log (typeof 3.1415 ) ; // number // 5.) boolean console.log (typeof true ) ; // boolean // 6.) undefined var notExistsOne; console.log (typeof notExistsOne) ; // undefined console. log (typeof notExistsTwo) ; // undefined

// 1.) object console.log(typeof()); // object var p = (x: 1, y: 3); console.log(typeofp); // object // 2.) function function sayHello() ( console.log("Hello!"); ) console.log(typeof sayHello); // function // 3.) string console.log(typeof "JavaScript"); // string // 4.) number console.log(typeof 3.1415); // number // 5.) boolean console.log(typeof true); // boolean // 6.) undefined var notExistsOne; console.log(typeof notExistsOne); // undefined console.log(typeof notExistsTwo); // undefined

note that undefined it is also a data type that consists of a single value.

Cast

Type casting in programming is the conversion of a value of a variable of one type to a value of another type.
Often this transformation occurs without the programmer's control. This can be seen in the example with the function sum. A type change occurs when the result of performing an operation on a variable of the original type is not clear. For example, it is impossible to say exactly what will result from adding a string with a number, but the operation of adding two numbers is obvious, and in this case it is logical to bring the number to the string.

Convert string to number

Sometimes the programmer himself can change the type of a variable by applying some operations to it. For example, increment or decrement operations on a string will convert it to a number.

var c = "not-a-number"; ++c; console.log(typeof c); // NaN

It is worth noting that you do not need to resort to this method of converting a string to a number because of its poor readability and non-obviousness. There are built-in functions in js for this task. parseInt and parseFloat. They take as their first argument a string to be converted to a number, and as their optional second argument, they take the base of the number system that contains the number in the string passed as the first argument. If the second argument is not specified, then it will be considered that the string contains a number in decimal system reckoning.

Function parseInt is used to convert a string to an integer, and the function parseFloat to convert to fractional.

var a = parseInt("10") ; console. log ([ "a = " , a, "; typeof a:" , typeof a] .join (" " ) ) ; // a = 10 ; typeof a: number var pi = parseInt("3.1415" ) ; console.log("pi = " + pi) ; // pi = 3 pi = parseFloat("3.1415" ) ; console.log("pi = " + pi) ; // pi = 3.1415

var a = parseInt("10"); console.log(["a = ", a, "; typeof a:", typeof a].join(" ")); // a = 10 ; typeof a: number var pi = parseInt("3.1415"); console.log("pi = " + pi); // pi = 3 pi = parseFloat("3.1415"); console.log("pi = " + pi); // pi = 3.1415

Note that the string can contain any literal numeric value, including hexadecimal, octal, or exponential.

a = parseInt("010") ; console.log("a = " + a) ; // a = 8 a = parseInt("0xAA" ) ; console.log("a = " + a) ; // a = 170 a = parseFloat("1e-10" ) ; console.log("a = " + a) ; // a = 1e-10 (1e-10 = 1 * 10^-10 = 0.0000000001)

a = parseInt("010"); console.log("a = " + a); // a = 8 a = parseInt("0xAA"); console.log("a = " + a); // a = 170 a = parseFloat("1e-10"); console.log("a = " + a); // a = 1e-10 (1e-10 = 1 * 10^-10 = 0.0000000001)

As the second parameter of the functions parseInt and parseFloat you can specify the base of the number system.

a = parseInt("10" , 8 ) ; console.log("a = " + a) ; // a = 8 a = parseInt("010" , 10 ) ; console.log("a = " + a) ; // a = 10 a = parseInt("ff" , 16 ) ; console.log("a = " + a) ; // a = 255

a = parseInt("10", 8); console.log("a = " + a); // a = 8 a = parseInt("010", 10); console.log("a = " + a); // a = 10 a = parseInt("ff", 16); console.log("a = " + a); // a = 255

If the value is in the string, which the functions parseInt and parseFloat take as the first parameter, is not a numeric literal, then the result of executing these functions will be the value NaN.

a = parseInt("not a number") ; console.log("a = " + a) ; // a = NaN a = parseFloat("not a number" ) ; console.log("a = " + a) ; // a = NaN

a = parseInt("not a number"); console.log("a = " + a); // a = NaN a = parseFloat("not a number"); console.log("a = " + a); // a = NaN

String conversion

AT JavaScript value any type can be cast to a string. It has already been said above that when a string is concatenated with a number, the number is reduced to a string, and only then does the concatenation take place. This will happen with any value type.

var str = "Object: " + ( ) ; console log (str) ; // Object: str = "Array: " + [ 1 , 2 , 3 ] ; console log (str) ; // Array: 1,2,3 function sum(a, b) ( return a + b; ) str = "Function: " + sum; console log (str) ; /* Function: function sum(a, b) ( return a + b; ) */

var str = "Object: " + (); console log(str); // Object: str = "Array: " + ; console log(str); // Array: 1,2,3 function sum(a, b) ( return a + b; ) str = "Function: " + sum; console log(str); /* Function: function sum(a, b) ( return a + b; ) */

In fact, when casting an object to a string, the method is implicitly called toString, which can also be called explicitly.

var p = ( x: 2 , y: 4 ) , str; str = p.toString(); console. log (typeof str) ; // string console.log (str) ; // str = [ 1 , 2 , 3 ] .toString () ; console. log (typeof str) ; // string console.log (str) ; // 1,2,3

var p = (x: 2, y: 4), str; str = p.toString(); console.log(typeofstr); // string console.log(str); // str = .toString(); console.log(typeofstr); // string console.log(str); // 1,2,3

Numeric Conversion

Conversion to a number occurs when performing mathematical operations and when performing a comparison operation with type casting (==, !=), while the value false and an empty array are converted to a value of type 0 number.

var a = true + true + true; // 1 + 1 + 1 console.log(a); // 3

A non-empty array, object, and function are cast to a string when used in arithmetic expressions.

var arr = [ 1 , 2 , 3 ] ; console.log (arr + 4 ) ; // 1,2,34 function sum(a, b) ( return a + b; ) console.log (sum + 5 ) ; // function sum(a, b)(return a + b;)5

var arr = ; console.log(arr + 4); // 1,2,34 function sum(a, b)(return a + b;) console.log(sum + 5); // function sum(a, b)(return a + b;)5

As you can see, implicit type conversion in js is far from always obvious, so you should avoid it by using functions for explicit type conversion, such as parseInt, parseFloat and toString.

That's all. As always, good luck to you!

Last update: 1.11.2015

Often there is a need to convert one data to another. For example:

varnumber1 = "46"; varnumber2 = "4"; varresult = number1 + number2; console log(result); //464

Both variables represent strings, more specifically string representations of numbers. And as a result, we will get not the number 50, but the string 464. But it would be nice if they could also be added, subtracted, in general, work like with ordinary numbers.

In this case, we can use transform operations. The function is used to convert a string to a number. parseInt():

varnumber1 = "46"; varnumber2 = "4"; var result = parseInt(number1) + parseInt(number2); console log(result); // 50

To convert strings to fractional numbers, use the function parseFloat():

varnumber1 = "46.07"; varnumber2 = "4.98"; var result = parseFloat(number1) + parseFloat(number2); console log(result); //51.05

In this case, the string can have mixed content, for example, "123hello", that is, in this case there are numbers, but there are also regular symbols. But the parseInt() method will still try to do the conversion:

Varnum1 = "123hello"; varnum2 = parseInt(num1); console log(num2); // 123

If the method fails to convert, it returns NaN (Not a Number), which indicates that the string does not represent a number and cannot be converted.

With special function isNaN() you can check if a string represents a number. If the string is not a number, then the function returns true, if it is a number, then false:

Var num1 = "javascript"; varnum2 = "22"; varresult = isNaN(num1); console log(result); // true - num1 is not a number result = isNaN(num2); console log(result); // false - num2 is a number

Above, we considered the translation of strings into numbers in the decimal system. However, we can translate numbers into any system. By default, the JavaScript interpreter itself guesses which number system we want to convert the string to (usually, the decimal system is selected). But we can use the second parameter to explicitly indicate that we want to convert a string to a number in certain system. For example, converting to a number in binary system:

Varnum1 = "110"; varnum2 = parseInt(num1, 2); console log(num2); // 6

The result will be 6, since 110 in binary is the number 6 in decimal.

Now let's write a small program in which we use operations with variables:

JavaScript

With the help of the prompt() function, a dialog box is displayed in the browser asking you to enter some value. The second argument to this function specifies the value to be used by default.

However, the prompt() function returns a string. Therefore, we need to convert this string to a number in order to perform operations with it.

After opening the page in the browser, we will see an invitation to enter the deposit amount:

Then a similar message will be displayed for entering the percentage. And at the end, the program will receive the data, convert it to numbers, and perform the calculation.

The parseInt() function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems).

The source for this interactive example is stored in a GitHub repository. If you"d like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

Syntax

parseInt(string , radix)

Parameters

string The value to parse. If this argument is not a string, then it is converted to one using the ToString abstract operation. Leading whitespace in this argument is ignored. radix Optional An integer between 2 and 36 that represents the radix (the base in mathematical numeral systems) of the string . Be careful this does not default to 10 ! The explains in more detail what happens when radix is ​​not provided.

return value

An integer parsed from the given string .

If the radix is ​​smaller than 11 , and the first non-whitespace character cannot be converted to a number, NaN is returned.

Description

The parseInt function converts its first argument to a string, parses that string, then returns an integer or NaN .

If not NaN , the return value will be the integer that is the first argument taken as a number in the specified radix . (For example, a radix of 10 converts from a decimal number, 8 converts from octal, 16 from hexadecimal, and so on.)

For radices above 10 , letters of the English alphabet indicate numerals greater than 9 . For example, for hexadecimal numbers (base 16), A through F are used.

If parseInt encounters a character that is not a numeral in the specified radix , it ignores it and all succeeding characters and returns the integer value parsed up to that point. parseInt truncates numbers to integer values. Leading and trailing spaces are allowed.

Because some numbers use the e character in their string representation (e.g. 6.022e23 for 6.022 × 10 23), using parseInt to truncate numbers will produce unexpected results when used on very large or very small numbers. parseInt should not be used as a substitute for Math.floor() .

parseInt understands exactly two signs: + for positive, and - for negative (since ECMAScript 1). It is done as an initial step in the parsing after whitespace is removed. if no signs are found, the algorithm moves to the following step; otherwise, it removes the sign and runs the number-parsing on the rest of the string.

If radix is ​​undefined , 0 , or unspecified, JavaScript assumes the following:

  1. If the input string begins with "0x" or "0X" (a zero, followed by lowercase or uppercase X), radix is ​​assumed to be 16 and the rest of the string is parsed as a hexidecimal number.
  2. If the input string begins with "0" (a zero), radix is ​​assumed to be 8 (octal) or 10 (decimal). Exactly which radix is ​​chosen is implementation-dependent. ECMAScript 5 clarifies that 10 (decimal) should be used, but not all browsers support this yet. For this reason always specify a radix when using parseInt.
  3. If the input string begins with any other value, the radix is ​​10 (decimal).

If the first character cannot be converted to a number, parseInt returns NaN unless the radix is ​​bigger than 10 .

For arithmetic purposes, the NaN value is not a number in any radix. You can call the isNaN function to determine if the result of parseInt is NaN . If NaN is passed on to arithmetic operations, the operation result will also be NaN .

To convert a number to its string literal in a particular radix, use thatNumber .toString(radix) .

Examples

Using parseInt

The following examples all return 15:

ParseInt("0xF", 16) parseInt("F", 16) parseInt("17", 8) parseInt(021, 8) parseInt("015", 10) // but `parseInt(015, 10)` will return 13 parseInt(15.99, 10) parseInt("15,123", 10) parseInt("FXX123", 16) parseInt("1111", 2) parseInt("15 * 3", 10) parseInt("15e2", 10) parseInt("15px", 10) parseInt("12", 13)

The following examples all return NaN:

ParseInt("Hello", 8) // Not a number at all parseInt("546", 2) // Digits other than 0 or 1 are invalid for binary radix

The following examples all return -15:

ParseInt("-F", 16) parseInt("-0F", 16) parseInt("-0XF", 16) parseInt(-15.1, 10) parseInt("-17", 8) parseInt("-15", 10) parseInt("-1111", 2) parseInt("-15e1", 10) parseInt("-12", 13)

The following examples all return 4:

ParseInt(4.7, 10) parseInt(4.7 * 1e22, 10) // Very large number becomes 4 parseInt(0.00000000000434, 10) // Very small number becomes 4

The following example returns 224:

ParseInt("0e0", 16) parseInt("123_456") // 123

Octal interpretations with no radix

Although discouraged by ECMAScript 3 and forbidden by ECMAScript 5, many implementations interpret a numeric string beginning with a leading 0 as octal. The following may have an octal result, or it may have a decimal result. Always specify a radix to avoid this unreliable behavior.

ParseInt("0e0") // 0 parseInt("08") // 0, because "8" is not an octal digit.

ECMAScript 5 removes octal interpretation

The ECMAScript 5 specification of the function parseInt no longer allows implementations to treat Strings beginning with a 0 character as octal values. ECMAScript 5 states:

The parseInt function produces an integer value dictated by interpretation of the contents of the string argument according to the specified radix. Leading white space in string is ignored. If radix is ​​undefined or 0 , it is assumed to be 10 except when the number begins with the character pairs 0x or 0X , in which case a radix of 16 is assumed.

This differs from ECMAScript 3, which discouraged but allowed octal interpretation.

Many implementations have not adopted this behavior as of 2013, and because older browsers must be supported, always specify a radix.

A stricter parse function

It is sometimes useful to have a stricter way to parse integers.

Regular expressions can help:

Function filterInt(value) ( ​​if (/^[-+]?(\d+|Infinity)$/.test(value)) ( return Number(value) ) else ( return NaN ) ) console.log(filterInt("421 ")) // 421 console.log(filterInt("-421")) // -421 console.log(filterInt("+421")) // 421 console.log(filterInt("Infinity")) // Infinity console.log(filterInt("421e+0")) // NaN console.log(filterInt("421hop")) // NaN console.log(filterInt("hop1.61803398875")) // NaN console.log (filterInt("1.61803398875")) // NaN

Specifications

Specification Status Comment
ECMAScript 1st Edition (ECMA-262) standard initial definition.
ECMAScript 5.1 (ECMA-262)
standard
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of "parseInt" in that specification.
standard
ECMAScript Latest Draft (ECMA-262)
The definition of "parseInt" in that specification.
Draft

Browser compatibility

The compatibility table on this page is generated from structured data. If you"d like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

Update compatibility data on GitHub

DesktopMobileserver
ChromeedgeFirefoxInternet ExplorerOperasafariandroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
parseIntChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 3Opera Full support YesSafari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Safari iOS Full support YesSamsung Internet Android Full support 1.0nodejs Full support Yes
Parses leading-zero strings are decimal, not octalChrome Full support 23Edge Full support 12Firefox Full support 21IE Full support 9Opera Full support YesSafari Full support 6WebView Android Full support 4.4Chrome Android Full support 25Firefox Android Full support 21Opera Android Full support YesSafari iOS Full support 6Samsung Internet Android Full support Yesnodejs Full support Yes

JavaScript has 2 built-in functions for converting strings to numbers: parseFloat() and parseInt() .

parseFloat() takes as an argument a string to be converted to a numeric type and returns a float number. The number must be at the beginning of the line. If there are any other characters after the number in the string, they are cut off. The fractional part of the number must be written through a period (the comma is not perceived as a separator). In case parseFloat() cannot convert the string, then it returns NaN.

Also, the function can process "the number n multiplied by 10 to the power of x", which is usually written in programming through the letter E, for example: 0.5E6 or 0.5E+6. The degree can also be negative: 0.5E-6, which is equal to 0.5*10^-6 or 0.5/1000000.

ParseFloat(""3.78kg"") // 3.78 parseFloat(""kg33"") // NaN parseFloat(""0004.111"") // 4.111 parseFloat(""0x66"") // 0 parseFloat("". 5"") // 0.5 parseFloat(""-.5"") // -0.5 parseFloat(""0.5e6"") // 500000 parseFloat(""0.03E+2"") // 3 parseFloat(" "3E-4"") // 0.0003 parseFloat(""-3E-4"") // -0.0003

The parseInt(string[, radix]) function takes a string as its first argument, parses it, and returns an integer (integer type). The function tries to parse the number system in which the number in the source string is written (for example, decimal, octal or hexadecimal - but not only these). Also, the number system can be specified explicitly by passing it as the second parameter to radix. The radix parameter can take any number between 2 and 36 (systems above 10 use the English alphabet, A through Z).

Numbers like 1.5e6 are not handled in the same way as parseFloat() .

Please read the examples below so as not to run into the pitfalls hidden in the work of the parseInt() function.

ParseInt(""25"") // 25 parseInt(""-25"") // -25 parseInt(""45.12"") // 45 parseInt(""045"",10) // 45 parseInt( ""70"",8) // 56 (70 in octal is 56 in decimal) parseInt(""070"") // 56 (IMPORTANT!!! zero first will cause the function to parse the string as an octal number) parseInt(" "88"",8) // NaN (there is no digit 8 in octal system) parseInt(""a1"") // NaN (IMPORTANT!!! The default function does not treat the number as hexadecimal unless you add it at the beginning strings 0x) parseInt(""a1"",16) // 161 (the number system is explicitly specified here) parseInt(""0xa1"") // 161 (correct hexadecimal format, the second parameter can be omitted) parseInt( ""099"") // 0 (IMPORTANT!!! The number is treated as octal but contains invalid characters) parseInt(""0.5e6"") // 0 (IMPORTANT!!! does not work like parseFloat) parseInt("" ZZ"",36) // 1295 parseInt(""-FF"") // NaN parseInt(""-FF"",16) // -255

If you are processing data from a text field that the user enters, always use parseInt() along with the second radix parameter, this will protect your code from unexpected results.

It doesn't matter what type of variable is used in the expression. If the expression is mathematical, all its variables will automatically be interpreted as numeric. If strings are processed, then all "participants" of the expression are treated as strings. However, the task of converting JavaScript "string to number" exists in a much broader context.

JavaScript Methods for Converting Strings to Numbers

The arsenal of methods for converting strings to numbers is not great, but sufficient in all simple cases. Here JavaScript (for beginners especially) is the way from simple to complex with practical examples.

The example describes four different strings. In the first output block, the type of each variable function typeof is defined as string. Each string is then very simply converted to a number. In the second output block, you can see the changes in the variables after the conversion, their type has become a number. The JavaScript parseFloat conversion example is especially revealing: it was "12e+3", now it's "12000".

Changes when converting a string to a number can be significant! But only the first characters matter: they must be numeric. If there are no numeric characters, the result will be NaN.

The reverse conversion of a string that "becomes" a number is not always the same string. This moment can be used to check the correctness of entering numerical information.

Conventional Conversion Methods

There are integers and there are fractional ones, respectively, JavaScript converts a string into a number by:

  • parseInt;
  • parseFloat.

The general case is implemented by using a string in a simple mathematical expression.

It is enough to put a "+" sign in front of the character string and, if it contains a number, then the result of the expression will be a number. The value of a variable may change, but the type will always change: typeof will show a number, not a string. It's important to understand that using a converted variable in a string expression can produce a very different result.

JavaScript for beginners in this context is extremely simple. It is more difficult to understand the operation of the integer conversion by the pasrseInt method, since it automatically works in decimal notation, but can interpret the string as octal or hexadecimal. However, this circumstance does not always depend on the second parameter, which indicates the number system.

JavaScript will always turn a string into a number, but if there is not a single numeric character at the beginning of the string in the string, then the result will be NaN.

You need to have an idea about number systems, how to write hexadecimal (number starts with "0x") and octal numbers (number starts with "0").

To understand the nuances of the JavaScript parseFloat method, it is enough to have an idea of ​​\u200b\u200bwhat the mathematical notation of a real number is.

Transformation for sorting

JavaScript is a browser language, which is why it is more critical than other languages ​​for characters outside the basic set of the Latin alphabet and numbers. Sorting is a popular operation. But it does not always make sense to send data to the server for sorting purposes, it is easier and more practical to do the work on the spot, in the browser.

To solve this problem, you can convert the characters of a string to their numeric codes, or assign letters and numbers to an ordered sequence of digits. The charCodeAt() method applied to a string will assign the numeric value 98 to the variable iB, i.e. the code of the letter "b". Given that the code value of the letter "a" is 97, you can get the numbers of all letters of the Latin alphabet in ascending order in lowercase and uppercase sets. Similarly for the letters of the Russian alphabet.

Own version of sorting through numbers allows you to form the desired character sets. You can, for example, “replace” the Cyrillic and Latin alphabets or mix them in order to leave only letters that are different in spelling, add tabs and spaces to the sets.

Formation of a unique string number

If the code for the letter "a" is 97, then the difference between the letter and the number 97 will give the unique number of the letter in the alphabet. By summing the unique numbers over each character of a string, it is difficult to get the unique number of that string.

If each position of a letter in a string is assigned a weight, for example position:

  • 0 weight 1;
  • 1 weight 10;
  • 2 weight 100;

then by multiplying the unique number of each character of the string by the weight of the position in which it was found, and summing all the numbers, you can get a unique number and use it as a one-to-one correspondence with the original string.

Such a conversion of a string into a number is reversible, that is, by the number you can always get the original string. Such a conversion is beneficial, because any operation can be safely performed with a number in the context of the encoding, Cyrillic and other local features of the site page, scope, visitor's country.

“Growing” website page selectors

Often there is a task of creating selectors on the pages of the site, the values ​​of which cannot be specified in advance, but over time they are supplemented. In the very first application, the empty selector is available to the first visitor to enter information.

Each new entry of a string of information into the selector (by any visitor) is transformed into a number, which, along with the original, is sent to the server for storage. When a new session starts or a new visitor arrives, the selector is no longer empty. The page on load comes to the browser with a non-empty selector.

With each new selector value, only once is it sent to the server for storage, and only once is it assigned a unique numeric code.

You cannot use the JavaScript string to number method to solve this problem. The usual parseInt and parseFloat methods are designed for other uses, but you can come up with an algorithm to uniquely convert a string to a number, and not necessarily reversible. It is enough that the conversion algorithm will not be repeated on different character sets in the string.

Traffic optimization and analytics

When forming a page, the developer uses significant amounts of information. Allow the visitor to enter information - good way lower the rating of the site due to its poor functionality and disappoint the visitor.

By assigning an event handler in the form of a JavaScript function to the visitor's actions for certain blocks of information, it is possible to formulate a filter that will allow the visitor to accurately set a goal, find the necessary information, and get the desired solution.

The transformation of string information here can be arbitrarily capacious in the string part and very small in the number part. In other words, the developer performs the transformation of a JavaScript string into a number according to his own algorithm. The visitor manipulates understandable information, and the minimum amount of data - a number - goes to the server.

The dynamics of a set of numbers for all visitors in the context of exactly known information allows another JavaScript function (not a handler) called on the server response through the AJAX mechanism to quickly and in real time give all visitors the necessary information at the same time. That's how the system works.

This way of converting a JavaScript string to a number is very popular in the development of online games, interactive conferences, instant messaging, and so on.

Instrumental application of transformations

JavaScript and CSS in the context of processing numerical information allow you to control the display of the page without the participation of the server. CSS Rules built as substrings, recursively. Usually the parameter is a number followed by several letters (eg "px", "pt", "em", ...). The parameter is a substring in the rule, and the rule is a substring in the style of the class or identifier.

Recursion JavaScript.Substring.Substring... reaches the desired number, converts from string to number, changes it and writes back Right place. The rule changes automatically. It's simple and convenient, no server involvement.