Set the value of double variable always with 3 digits decimal dot | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
- 2

Set the value of double variable always with 3 digits decimal dot

Hi everyone In my code , user can input some numbers like : 2 7.2 8.444 9.728288 I want to set the values like this : 2.000 7.200 8.444 9.728 I want to set the value of double variables like that , not just print them . Because I want to work with them . Line Subtracting , multipluing and so on . In another words I don't want to assign these values to string variable . Because I can't work with them Thanks

20th Feb 2021, 6:14 AM
Bruce
3 Réponses
- 1
visph It is not my answer . But i have gotten idea from that . First i calculate with my numbers when my work was complete , then I set the value to 3 digit . so the result value that printed , converted to String
20th Feb 2021, 8:00 AM
Bruce
+ 1
printf("%.3f",num);
20th Feb 2021, 6:19 AM
visph
visph - avatar
0
♨ Soumik 🎶 It is not true . If the d variable was 6.1 , returns 6.1 . Or if the d variable was 2 , returns 2.0 . But I want to print 6.100 and 2.000 . The answer is my description in answer 2 Thanks you ...
20th Feb 2021, 8:52 AM
Bruce