Why is double printing the same value as float in C when they have different sizes?

Advertisements I need to do calculations using π. When I checked precision of M_PI, it only printed 7 decimal digits. So I #defined my own MY_PI. But I am still facing the same problem. double should support 15-17 decimal digits. Why am I only getting 6 #define MY_PI 3.1415926535897932384626433832795028841971 #include<stdio.h> #include<math.h> int main() { printf("%f\n%lf\n%20lf\n",M_PI,M_PI,M_PI);… Read More Why is double printing the same value as float in C when they have different sizes?

Cannot convert from double to float Error

Advertisements I’m writing a simple program that converts pounds to kilos, but I’m a bit confused import java.util.Scanner; public class FiveTenOne { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); //Creates Scanner Object System.out.print("Enter your weight in pounds: "); float pounds = keyboard.nextFloat(); float kilos = pounds / 2.2; System.out.print("Your value in… Read More Cannot convert from double to float Error

Data type conversion problem for leetcode pratice "Moving Average from Data Stream"

Advertisements When I was running the code for the leetcode question ""Moving Average from Data Stream"". I got a partly different output with the expected: Here is my code: class MovingAverage { int front = 0, rear = 0; Double sum = 0.00000; int[] data; public MovingAverage(int size) { data = new int[size]; Arrays.fill(data, 0);… Read More Data type conversion problem for leetcode pratice "Moving Average from Data Stream"

Why does misusing 1 instead of 1.0 from an int exceeding limits effect the value we get when we convert it to a double

Advertisements This is the code I will be using… public class foo { public static void main(String [] args){ int a = (int) Math.pow(2, 30); double d = (a + a – 1.0); double f = (a + a – 1); System.out.println(d); System.out.println(f); } } The outputs are -2.147483649E9 and 2.147483647E9. I do not understand… Read More Why does misusing 1 instead of 1.0 from an int exceeding limits effect the value we get when we convert it to a double

how to fix double in flutter even if the last decimal is 0

Advertisements Hi so i have a double seems like this d1 = 12.106 and i need to show in to a string ‘12.130’ double num1 = double. parse((12.3404). toStringAsFixed(3)); well i expected to return "12.130" but it returned "12.13" the thing i need a string "12.130" instead "12.13" double num1 = double. parse((12.3404). toStringAsFixed(4)); so… Read More how to fix double in flutter even if the last decimal is 0