String converted to a numeric percentage, etc.

Source: Internet
Author: User

parsefloat is a global function and does not belong to any object.

Parsefloat parses its string argument into a floating-point number and returns it. If a character other than a sign (+ or-), a number (0-9), a decimal point, or an exponent (e or E) in scientific notation is encountered during parsing, it ignores the character and all subsequent characters, returning the currently resolved floating-point number. Whitespace characters at the top of the parameter string are ignored.

If the first character of the argument string cannot be parsed into a number, parsefloat returns NaN.

Tip: You can call the IsNaN function to determine whether the return result of Parsefloat is NaN. If Nan is used as the operand of any mathematical operation, the result of the operation must also be Nan.

Example:

<script type= "Text/javascript" >document.write (parsefloat ("ten")) document.write (parsefloat ("10.00")) document.write ("10.33") document.write (parsefloat ("parsefloat") document.write (parsefloat ("60")) document.write (parsefloat ("Years")) document.write (parsefloat ("He was")) </script>
Output:
101010.33346040NaN
Decimal is retained

parseint ()
Parameters:

Here are the details of the parameters:

    • String S: This is the string representation of the decimal.

    • int radix: This will be used to convert the string to an integer.

return Value:
    • parseint (String s): This returns a integer (decimal only).

    • parseint (int i): This returns an integer, given a string representation of decimal, binary, octal, or hexadecimal (radix e Quals, 2, 8, or respectively) numbers as input.

Example:
public class test{public    static void Main (String args[]) {      int x =integer.parseint ("9");      Double C = double.parsedouble ("5");      int B = Integer.parseint ("444", +);//by Www.yiibai.com/java      System.out.println (x);      System.out.println (c);      System.out.println (b);   }}

This will output the following results:

95.01092


Parsefloat (the value of the string). ToString (). Replace (/(\.\d{2}) \d+$/, "$");(reserved Two decimal places will not be rounded);
If you want to increase the percentage, write this:

Parsefloat (value of String) *100). ToString (). Replace (/(\.\d{2}) \d+$/, "$") + '% '; the inside of the multiply 100 or divided by 100 to see the specific conversion type, decimal, the whole number is divided.
parseint () and parsefloat () two methods are searched from the left string, if the first character is not a number or a minus sign (in parsefloat () it can also be a decimal point). Once they encounter such a character, they return the number they extracted.

String converted to a numeric percentage, etc.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.