Retrieve numbers after comma (from double numbers)

pMpC

Imagine that I have 4,81 (double), how can i get the figures after the comma?

I want to receive 8 as a Integer and 1 as another.

Thanks

aioobe

Doubles are tricky to work with when you're interested in decimal properties such as the decimal digits of the fractional part.

I suggest you let String.valueOf do the transformation to decimal digits and work with the resulting string.

double d = 4.81;
String s = String.valueOf(d);

for (int i = s.indexOf(".") + 1; i < s.length(); i++) {
    int digit = Character.getNumericValue(s.charAt(i));
    System.out.println(digit);
}

Output:

8
1

Collected from the Internet

Please contact debug[email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Get mean of numbers in character string before and after comma

From Java

Pandas convert numbers with a comma instead of the point for the decimal separator from objects to numbers

From Dev

regex for numbers comma and space

From Dev

Validate comma separated numbers

From Dev

Limit string to 2 numbers after comma and only ONE comma

From Dev

Print line numbers from grep separated with a comma

From Dev

Remove a Number from List of Comma-Separated Numbers

From Dev

match only letters after comma without numbers

From Dev

retrieve numbers from a string with regex

From Dev

Reading comma and space separated numbers from a text file

From Dev

R - retrieve row numbers after sorting

From Dev

PHP Add double quotes before and after numbers in json string

From Dev

Strip double qoutes only from the numbers JS

From Dev

Output numbers with comma after 3 digits

From Dev

Rounding numbers to 2 digits after comma in oracle

From Dev

How to set only two numbers that appear after the comma when exporting reports to excel from PHP?

From Dev

Converting a string of comma separated numbers into numbers

From Dev

Retrieve phone numbers from customer

From Dev

Retrieve Numbers After Certain Part of String

From Dev

Cutting numbers after the comma

From Dev

Convert decimal numbers from string to double

From Dev

Getting double numbers from array_rand

From Dev

Reading comma and space separated numbers from a text file

From Dev

Regex to retrieve numbers from string

From Dev

Rounding numbers to 2 digits after comma in oracle

From Dev

Wildcard list of numbers after comma and join on single value

From Dev

Retrieve numbers and turn as star

From Dev

Int won't show numbers after the comma

From Dev

Removing comma from numbers in R

Related Related

  1. 1

    Get mean of numbers in character string before and after comma

  2. 2

    Pandas convert numbers with a comma instead of the point for the decimal separator from objects to numbers

  3. 3

    regex for numbers comma and space

  4. 4

    Validate comma separated numbers

  5. 5

    Limit string to 2 numbers after comma and only ONE comma

  6. 6

    Print line numbers from grep separated with a comma

  7. 7

    Remove a Number from List of Comma-Separated Numbers

  8. 8

    match only letters after comma without numbers

  9. 9

    retrieve numbers from a string with regex

  10. 10

    Reading comma and space separated numbers from a text file

  11. 11

    R - retrieve row numbers after sorting

  12. 12

    PHP Add double quotes before and after numbers in json string

  13. 13

    Strip double qoutes only from the numbers JS

  14. 14

    Output numbers with comma after 3 digits

  15. 15

    Rounding numbers to 2 digits after comma in oracle

  16. 16

    How to set only two numbers that appear after the comma when exporting reports to excel from PHP?

  17. 17

    Converting a string of comma separated numbers into numbers

  18. 18

    Retrieve phone numbers from customer

  19. 19

    Retrieve Numbers After Certain Part of String

  20. 20

    Cutting numbers after the comma

  21. 21

    Convert decimal numbers from string to double

  22. 22

    Getting double numbers from array_rand

  23. 23

    Reading comma and space separated numbers from a text file

  24. 24

    Regex to retrieve numbers from string

  25. 25

    Rounding numbers to 2 digits after comma in oracle

  26. 26

    Wildcard list of numbers after comma and join on single value

  27. 27

    Retrieve numbers and turn as star

  28. 28

    Int won't show numbers after the comma

  29. 29

    Removing comma from numbers in R

HotTag

Archive