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

*1*### Get mean of numbers in character string before and after comma

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

*3*### regex for numbers comma and space

*4*### Validate comma separated numbers

*5*### Limit string to 2 numbers after comma and only ONE comma

*6*### Print line numbers from grep separated with a comma

*7*### Remove a Number from List of Comma-Separated Numbers

*8*### match only letters after comma without numbers

*9*### retrieve numbers from a string with regex

*10*### Reading comma and space separated numbers from a text file

*11*### R - retrieve row numbers after sorting

*12*### PHP Add double quotes before and after numbers in json string

*13*### Strip double qoutes only from the numbers JS

*14*### Output numbers with comma after 3 digits

*15*### Rounding numbers to 2 digits after comma in oracle

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

*17*### Converting a string of comma separated numbers into numbers

*18*### Retrieve phone numbers from customer

*19*### Retrieve Numbers After Certain Part of String

*20*### Cutting numbers after the comma

*21*### Convert decimal numbers from string to double

*22*### Getting double numbers from array_rand

*23*### Reading comma and space separated numbers from a text file

*24*### Regex to retrieve numbers from string

*25*### Rounding numbers to 2 digits after comma in oracle

*26*### Wildcard list of numbers after comma and join on single value

*27*### Retrieve numbers and turn as star

*28*### Int won't show numbers after the comma

*29*### Removing comma from numbers in R

## Comments