Selecting a digit from a double?

Caporegime
Joined
12 Mar 2004
Posts
29,962
Location
England
Is there a simple way I can select a digit from a double and convert it to int?

I created this statement
Code:
Integer.parseInt((Double.toString(priceperlitre)).substring(0, 1))
which works fine, except that when the double is a different length than expected it can select the decimal point and an exception occurs when converting it to an int.
 
Last edited:
The problem is I have 3 seven segment displays, they have 3, 4 and 5 digits respectivley. So I will have to write 12 different assignment statements, and if I have to write if statements as well there will be well over 100 lines! I'm trying to think how to shrink the code down as much as possible.
 
Can you give an example of the input / output you want?

Do you just want the integer part of a double? i.e.

27.33 -> 27

Or do you want a specific digit, like the one always before the decimal place?

27.33 -> 7

A specific digit, each display will display one digit of the boolean.


What are you programming in?

Stelly

Java.

This is my code
 
Last edited:
Back
Top Bottom