+ 14
https://code.sololearn.com/csFI4mXJaFWc/?ref=app
https://code.sololearn.com/cNn10rmtfMQn/?ref=app
+ 14
https://code.sololearn.com/cVrn8XvBATA5/?ref=app
+ 9
nice
+ 5
+ 4
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
double a=sc.nextDouble();
double b=a-(Math.floor(a));
if(b!=0.0){
System.out.println(""+a+"is a double value");
}
else {
System.out.println(""+a+"is an integer value"+((int)(Math.floor(a))));
}
}
}
it's my try
+ 3
# Python
# number given as n
integ, dec = tuple(str(n).split("."))
result = "integer" if all(i == "0" for i in dec) else "decimal"
print(result)
+ 2
@nitish kumar jha - Comparing floating point values to absolute numbers (such as 0.0) isn't a good plan.
Some references:
Very technical - https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
More accessable - http://www.floating-point-gui.de/errors/comparison/
Here's my C solution. Instead of dealing with floating point comparisons, I convert the characters after the decimal point to an integer and compare that to zero. This solution won't work if the decimal point is not proceeded with a valid number (such as ".0232").
https://code.sololearn.com/c902hiAmNjBE
+ 2
My solution as pythoneliner:
https://code.sololearn.com/ca69PqsUzqT3/?ref=app
https://code.sololearn.com/cBbw6N6jOP70/?ref=app
+ 1
x.is_integer()
+ 1
C# shortest answer possible (I think)
60 Bytes
namespace a{class b{static bool c(float d){return d%1f==0}}}
EDIT: -1 byte due to 1f instead of 1.0
EDIT 2: yes, I like codegolf