There are two overloads of add method available in Java which is listed below: add (BigDecimal val) add (BigDecimal val, MathContext mc) add (BigDecimal val) Syntax: public BigDecimal add (BigDecimal val) Lets check out an example below to understand better. what is a ruling in a court case; chuckanut drive stops; sample email requesting h1b visa; pros and cons of bonds for companies; luxury bath salts south africa; affinity photo sketch macros; venetian plaster products; cisco router syslog configuration Making statements based on opinion; back them up with references or personal experience. Do peer-reviewers ignore details in complicated mathematical computations and theorems? remove decimal part in java. How to print formatted BigDecimal values? Toggle some bits and get an actual square. Not the 3 in 2.3. Method 3: Multiply and Divide the number with 10 n (n decimal places) In this approach, we first Multiply the number by 10 n using the pow() function of the Math class. This is a common requirement if you are working in the finance domain. How could magic slowly be destroying the world? Flake it till you make it: how to detect and deal with flaky tests (Ep. E.g (int) doubleValue. C++ Java Python3 C# Javascript // C++ program of number of leading zeros in // binary representation of a given number #include <bits/stdc++.h> using namespace std; To subscribe to this RSS feed, copy and paste this URL into your RSS reader. 1+. The cookie is used to store the user consent for the cookies in the category "Analytics". In order to remove the decimal point and trailing decimal parts or trailing zeros, we need to use the replaceAll method along with the regex pattern. My names Scott Miller. Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. Programming Languages: C, C++, Python, R, Java, JavaScript, This article will introduce how to fix the TypeError: > not supported between instances of [], This article will share with you how to multiply a range in Python. Flake it till you make it: how to detect and deal with flaky tests (Ep. It does not store any personal data. This might be a duplicate, but I cannot find any answers that work with my code. I want to add 0 in the version.How to set this with a float or double value-> 1.9 to 0.1.9?? Connect and share knowledge within a single location that is structured and easy to search. java remove leading zeros of a string. Would Marx consider salary workers to be members of the proleteriat? By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. Flake it till you make it: how to detect and deal with flaky tests (Ep. Connect and share knowledge within a single location that is structured and easy to search. If you want to covert to double, you need to find a build in function to covert to bigdecmical to double. I then try to write the results to a text file, but it's not showing like it should. 528), Microsoft Azure joins Collectives on Stack Overflow. How can we cool a computer connected on top of or within a human brain? Removing unreal/gift co-authors previously added because of academic bullying. How can i fix this? We connect IT experts and students so they can share knowledge and benefit the global IT community. Did Richard Feynman say that anyone who claims to understand quantum physics is lying or crazy? For example, if you have a decimal 3.25 in A1 and grams in B1, you can specify 6 decimal places with the following: Highlight the cells you would like to have 6 decimal points, then go to Format > Cells and from there select the number category, from there you can choose how many decimal points you would like. Here df.format() output is of string type. Major: IT I need a 'standard array' for a D&D-like homebrew game, but anydice chokes - how to proceed? But I need to send value as double. Otherwise they could just cast to an int. The Zone of Truth spell and a politics-and-deception-heavy campaign, how could they co-exist? You can create a method that returns the exact format for your decimals. Sorry guys, beginner's mistake. Why is executing Java code in comments with certain Unicode characters allowed? Why is 51.8 inclination standard for Soyuz? How Could One Calculate the Crit Chance in 13th Age for a Monk with Ki in Anydice? java remove leading zeros. It formats a string to produce a string. How to tell if my LLC's registered agent has resigned? Thanks for contributing an answer to Stack Overflow! For example, if We have a number=12, we have to output the number to 12.00 by adding two zeroes to the number. Share Improve this answer Follow answered Nov 20, 2021 at 0:34 Joo Dias Result of fee is 8.4, it should return 8.40, Result of fee is 8.0, it should return 8.00. If you have any questions, please leave a comment below. In javascript, numeric values represent in Number type. Could you observe air-drag on an ISS spacewalk? Need 30.40 not 30.4. I'm trying to add trailing zeroes to the right of a decimal number in Excel. You can use method stripTrailingZeros(), but it will give you "wrong" result: You can fix it by calling .toPlainString() and passing this to the BigDecimal constructor to let it handle correctly: Simple, clean, flexible, easy-2-understand and maintain code. add a decimal in front of a whole number python. And, keep the decimal to just 2. String str = String.format("%10d", 3); // 0000000003. At last, we divide the number by 10 n. By doing this, we get the decimal number up to n decimal places. There are two ways to do so: Multiply-and-divide. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. Example, turn 6.13 into 6.130000. Oh it has overhead? Video This method is used to add two specified decimal values. Site Maintenance- Friday, January 20, 2023 02:00 UTC (Thursday Jan 19 9PM Were bringing advertisements for technology courses to Stack Overflow, How to round a number to n decimal places in Java, How to get an enum value from a string value in Java. Toggle some bits and get an actual square, An adverb which means "doing without understanding". Return Value: Decimal sum of a1 & a2. But need to catch for ArithmeticException. For example, one of the most common tasks is to format a number for currency display- an integer followed by two decimals. To truncate a number, we miss off digits past a certain point in the number, filling-in zeros if necessary to make the truncated number approximately the same size as the original number. Site Maintenance- Friday, January 20, 2023 02:00 UTC (Thursday Jan 19 9PM Use of ChatGPT is now banned on Super User, Best way to remove leading zeros from a non-numeric value in Excel, Concatenating numbers that have leading zeros, Excel: Align by decimal point in cells with stars, Excel function that works out the average by first excluding all zeros and then excluding the minimum and maximum value. How dry does a rock/metal vocal have to be during recording? like if user enter some random value and gives that he wants accuracy till three digit then I need to round off the digit till three places after decimal. So while it makes sense in the context of all zeros, the reason one might go to the precision is implied that you may actually USE that precision, as such you may need to go out further (and truncate) if you want to avoid rounding errors). Now client is like we want those 4 zero after decimal points, i am really confused how to achieve this. There are two main ways to add zeros at the start of an integer number in Java, first by using format () method of String class, and second by using format () method of DecimalFormat class . For instance, we have 1.2345 and want to round it to 2 digits, getting only 1.23. * This method returns a String which contains padded zero. How to add zeros to a float after the decimal in Python, Make division by Zero return Zero in Python, Round a float DOWN to the nearest Integer in Python, How To Solve The TypeError: > not supported between instances of float and str, How To Convert A Boolean To An Integer In Python. * Scanner is skipping nextLine() after using next() or nextFoo()? Are there developed countries where elected officials can easily terminate government workers? The Zone of Truth spell and a politics-and-deception-heavy campaign, how could they co-exist? If you actually NEED to store the numbers as text, then you may want to create a virtual column: CREATE TABLE MyTable (COL1 VARCHAR2 (100), COL1_N NUMBER AS (TO_NUMBER (COL1)) ); Thanks in advance. Asking for help, clarification, or responding to other answers. Hi, guys! Appreciate if you can tell me some catchy statements, so i can convince him regarding this. How to tell if my LLC's registered agent has resigned? 5 Answers Sorted by: 8 It is because you are using Double.valueOf on the DecimalFormat and it is converting the formatted number back to a double, therefore eliminating the trailing 0s. Removing unreal/gift co-authors previously added because of academic bullying. *, // %08 means total length of number would be 8, // if number is of 3 digits, rest of them will, // You can also display hexadecimal number padded by zero, // just replace %d with %x, as shown below, // Another way to left pad a number is by using DecimalFormat class, // Below format will make String 6 digit long, // if number is less than 6 digit long, it will be padded by, formatting floating-point numbers in Java, % denotes that it's a formatting instruction, 4 denotes the length of formatted String, this will ensure that the right number of zero should be added. Learn JavaAdding leading zeroes to values in a minimum field widthDownload the Dr.Java Integrated Development Environment (IDE) - http://www.drjava.org/Thank. Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. How did adding new pages to a US passport use to work? I would use "#0.00" for my format String, but this should and will work. My current job is a software developer and I have shared a lot of quality articles about Javascript, C, C++, C#, Python, PHP, R, Java programming languages. Use the text to columns tool (under the data ribbon) and delimit by ". 60 (Guitar). It only takes a minute to sign up. For more information on the format syntax, check out DecimalFormat. How do I generate random integers within a specific range in Java? lualatex convert --- to custom command automatically? How is Fuel needed to be consumed calculated when MTOM and Actual Mass is known. lualatex convert --- to custom command automatically? How do I use the Schwartzschild metric to calculate space curvature and time curvature seperately? To get rid of unnecessary trailing zeros in the decimal number, we can make use of the Number () method. Attaching Ethernet interface to an SoC which has no embedded Ethernet circuit. Can't execute jar- file: "no main manifest attribute". Can I (an EU citizen) live in the US if I marry a US citizen? Meaning of "starred roof" in "Appointment With Love" by Sulamith Ish-kishor. Making statements based on opinion; back them up with references or personal experience. rev2023.1.17.43168. I need a 'standard array' for a D&D-like homebrew game, but anydice chokes - how to proceed? The above are all the ways that can help you learn about how to add zeros to a float after the decimal in Python. .6 zeros after point. 0 Popularity 4/10 Helpfulness 1/10 Language java. How could one outsmart a tracking implant? How can I pad an integer with zeros on the left? Thanks, I was about to use a more complicated formula calculating the number of places after the point: I have tried this, however I need to use the result to concatenate it with some text. How to automatically classify a sentence or text based on its context? loy you can use DecimalFormat class to add zeros after any decimal in Java, here is code as an example: Use this method to get always two decimals: private static String getTwoDecimals(double value . Difference between decimal, float and double in .NET? Share Improve this answer Follow edited Feb 14, 2013 at 22:08 I'm trying to truncate my results for a method(for calculating a fee) in Java. I would guess you are not really talking about "rounding" but formatting. Comment . All financial calculations should be done with BigDecimal. how to remove zero after decimal float python. look at the first digit after the decimal point if rounding to one decimal place or the second digit for two decimal places. This is a program that takes in two inputs then performs few calculations. is developed to help students learn and share their knowledge more effectively. We can also use Java BigDecimal Class for displaying a number up to two decimal places. Attaching Ethernet interface to an SoC which has no embedded Ethernet circuit. It also throws NullPointerException if we specify the format as null. preserve leading zeros python. Browse other questions tagged, Start here for a quick overview of the site, Detailed answers to any questions you might have, Discuss the workings and policies of this site, Learn more about Stack Overflow the company. Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide, But how do you KNOW if you should call intValueExact? How dry does a rock/metal vocal have to be during recording? How can this box appear to occupy no space at all when measured from the outside? How do I make Google Calendar events visible to others? Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. How to get rid of zero after decimal point? Can a span with display block act like a Div? lualatex convert --- to custom command automatically? To subscribe to this RSS feed, copy and paste this URL into your RSS reader. Here is an example: If you don't need to change the decimals value so often, then you can change your method to something like: You can indeed use NumberFormat to do this, String ar = String.format("%.3f", area); ar = 6.000. How were Acorn Archimedes used outside education? To easily format numbers for a specific number of trailing decimals or total digits (aka padding), JavaScript 1.5 introduces the below two nifty methods: Formats any number for x number of trailing decimals. Convert to a decimal using with toFixed (2) method. For example, consider the number 120. Kyber and Dilithium explained to primary school students? Formatting numbers for decimals and significant digits in JavaScript. Wall shelves, hooks, other wall-mounted things, without drilling? Can you give an example which didn't work? You can delimit your number by the decimal point, add trailing zeros, and finally combine your whole number with your decimal number. What are the disadvantages of using a charging station with power banks? Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. Flake it till you make it: how to detect and deal with flaky tests (Ep. sorry, wrong answer, try BigDecimal(200.0000), you get 2E+2, not the desired 200. By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. Double fee = 8.0; String formattedDouble = String.format ("%.2f", fee ); Note that a Double doesn't hold a formatted representation of its value. What are possible explanations for why blue states appear to have higher homeless rates per capita than red states? How can we cool a computer connected on top of or within a human brain? Comment . Optional. Thanks for contributing an answer to Stack Overflow! What happens when XML parser encounters an error? Super User is a question and answer site for computer enthusiasts and power users. 528), Microsoft Azure joins Collectives on Stack Overflow. You are formatting your double using: Then, you parse this string, back into a Double, therefore losing your formatting: Just return a String rather than a Double, and don't use Double.parseDouble. How to round a number to n decimal places in Java, Fastest way to determine if an integer's square root is an integer, 'Must Override a Superclass Method' Errors after importing a project into Eclipse, Rounding BigDecimal to *always* have two decimal places, I want to keep my trailing zeroes when using DecimalFormat. Can I (an EU citizen) live in the US if I marry a US citizen? The leading zeros are obtained by a Custom cell Format (0000000). While this code may answer the question, it would be better to explain. You can create a method that returns the exact format for your decimals. EXPLANATION. How to add n number of zeros after a decimal? Once it's round it, I know how to print it. It accepts rounding mode as a parameter and overrides the setRoundingMode() method of the NumberFormat class. Mail us on [emailprotected], to get more information about given services. ya, feels like this could help. Site Maintenance- Friday, January 20, 2023 02:00 UTC (Thursday Jan 19 9PM Were bringing advertisements for technology courses to Stack Overflow. Is the number of digits after the decimal point optional? * Java program to pad leading zeros into numbers e.g. How to round a number to n decimal places in Java, Fastest way to determine if an integer's square root is an integer. This cookie is set by GDPR Cookie Consent plugin. And my accuracy keeps changing. a2: This parameter specifies the second value to add. -1. Copyright 2011-2021 www.javatpoint.com. To do [], To convert a boolean to an integer in Python you can use some solutions such [], Your email address will not be published. An adverb which means "doing without understanding", Indefinite article before noun starting with "the", Attaching Ethernet interface to an SoC which has no embedded Ethernet circuit. This way you can control how your formatted numeric String will look like depending upon the locale. Carcassi Etude no. Asking for help, clarification, or responding to other answers. Finally, thank you for reading this article, good luck, and see you again! Rounding will eliminate them. These cookies ensure basic functionalities and security features of the website, anonymously. If you need m_interest calculations, keep it as a regular double. How do I convert a String to an int in Java? He needs it to show trailing 0s. How to do the rounding? remove zeros after decimal in java. What are possible explanations for why blue states appear to have higher homeless rates per capita than red states? This formula uses the & sign to insert a trailing zero to a number. or may be left_pad() and right_pad() to apply padding on left or right side of String. We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. If you don't want decimals either use an int or cast a double to an int. The number can be 12,-12,12.00. Why is water leaking from this hole under the sink? Making statements based on opinion; back them up with references or personal experience. Let's see an example. int val = 290; For adding 4 leading zeros above, we will use %07d i.e. How can I center a column in Excel, have the decimal points aligned, and show only the necessary decimal places for each number? Note that we cannot round the number in String.format() method, always rounding half-up. python fixed zeros after decimal. Can I change which outlet on a circuit has the GFCI reset switch? Is the rarity of dental sounds explained by babies not immediately having teeth? rev2023.1.17.43168. Why does setInterval keep sending Ajax calls? 5 How to round to 2 decimal places in JavaScript? The best answers are voted up and rise to the top, Not the answer you're looking for? If you dont know how to add zeros to a float after the decimal in Python, this article is perfect for you. Not the answer you're looking for? I recommend updating your question with that information even though you already have your problem solved, in case others have the same problem. Asking for help, clarification, or responding to other answers. I need to give accuracy of a number entered by user till few digit. Which are different things to me. Clean Cottonmouth. So please If you could give some way so that it gives the zeros after decimal as enterd by user. By clicking Accept All, you consent to the use of ALL the cookies. /** Find centralized, trusted content and collaborate around the technologies you use most. It works with string as well as number types. So i did something like this, but when user enters some value but do not enters any value as decimal I need to display it as dismal value with zeros as number of decimal places. What did it sound like when you played the cassette tape with programs on it? It throws NullPointerException if we do not specify any roundingMode. In that case, i think the answer by @LuiggiMendoza above will help you. By clicking Post Your Answer, you agree to our terms of service, privacy policy and cookie policy. Stack Exchange network consists of 181 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. Do you just wanna get rid of it or you want to round? Tags: Contributed on Nov 04 2022 . The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. By any chance, if you are stuck with Java 1.4 you can use, As I said, formatting is a very useful concept and you must master it. Christian Science Monitor: a socially acceptable source among conservative Christians? 528), Microsoft Azure joins Collectives on Stack Overflow. 528), Microsoft Azure joins Collectives on Stack Overflow. How could magic slowly be destroying the world? rev2023.1.17.43168. Thanks @aglassman for you explanation. Hope this helps. Java has a rich API and thankfully neither, So you need to either write a routine who is smart enough to add right numbers of zeros in front, as it varies depending upon input, or you can simply use, String.format() is my preferred solution because of it's extensive usage but it is only available from Java 1.5, so if your application has stuck in JDK 1.4, you cannot use it. The java.lang.Integer.numberOfLeadingZeros () is the method which returns the total number of zero (0) bits preceding the highest-order (ie.leftmost or most significant "1" bit)one-bit in the two's complement binary representation of the specified integer value or we can say that it is the function which converts int value to Binary then . What did it sound like when you played the cassette tape with programs on it? Why is water leaking from this hole under the sink? What is the origin and basis of stare decisis? Could you observe air-drag on an ISS spacewalk? .two decimal places, and so the result simply truncates it to the specified number of zeros that follow the decimal/radix character (D) in the format . Why is 51.8 inclination standard for Soyuz? It is because you are using Double.valueOf on the DecimalFormat and it is converting the formatted number back to a double, therefore eliminating the trailing 0s. In algorithms for matrix multiplication (eg Strassen), why do we say n is equal to the number of rows and not the number of elements in both matrices? Trailing zeros. Indefinite article before noun starting with "the". Using the format() function, we will represent a float to format the number with exactly N digits which you want to amount zeros after the decimal point. Card trick: guessing the suit if you see the remaining three cards (important is that you can't move or turn the cards), Fraction-manipulation between a Gamma and Student-t. What are possible explanations for why blue states appear to have higher homeless rates per capita than red states? How can citizens assist at an aircraft crash site? Can state or city police officers enforce the FCC regulations? it will format it with three digit. In the following example, we have an input field in which we will enter a random decimal number. Thanks in advance - Abtra16 Mar 21, 2015 at 20:30 What does "you better" mean in this context of conversation? How to directly initialize a HashMap (in a literal way)? what's the difference between "the killing machine" and "the machine that's killing". I am not able to display zero after decimal when it always changes. The method throws ArithmeticException if RoundingMode is set to UNNECESSARY. Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide. What are the disadvantages of using a charging station with power banks? In first example we have used, You can also add leading zeros in hexadecimal numbers by using, By using these methods you can easily pad as many zeros as you like because String has no range in Java. You should say what to use instead of .parseDouble. I used formula for the sheet ROUND((G49/C49)*100,J$46) (note: J$46 has round value, enable list option in J$46 so I can select 1, 2 or 3 round as per requirement) Solution 1: A naive approach is to convert the no. Your best wud be, store it as varchar2 column. How can I pad an integer with zeros on the left? There are so many legacy systems out there that expect the input of a certain length, and if your input is shorter than the specified length, you got to add zeros at the beginning of the number to make them off the right length. How To Add A Class To The Body Element In React. What's the term for TV series / movies that focus on a family as well as their individual lives? Hello Amon, you need to convert double to String and use String.format() method like String.format("0%.00d", doubleValue)to print in the format you want. Java : Removing zeros after decimal point in BigDecimal, tutorialspoint.com/java/math/bigdecimal_intvalueexact.htm, Flake it till you make it: how to detect and deal with flaky tests (Ep. :laugh: Posted 5-Apr-13 2:19am OriginalGriff Updated 5-Apr-13 2:38am v2 Comments I need a 'standard array' for a D&D-like homebrew game, but anydice chokes - how to proceed? These cookies will be stored in your browser only with your consent. How do I make a horizontal table in Excel? EDIT: After adding the trailing zeros, I need to use the resulting values inside another formula. To learn more, see our tips on writing great answers. Asking for help, clarification, or responding to other answers. If you also want to remove preceding zeroes as well then pls use this updated function: Public Function fnNumberwithoutzero (ByRef Value As String) fnNumberwithoutzero = 0. Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors. If you want a lot of digits before the decimal then simply add a lot of 9 s. Solution 2 datatype of a is number (12); Then use 12 9s in the format model. Remove Trailing zeros BigDecimal Java Post Last Updated: 19 Feb 2022 18:15 GMT | User: @c2cDev | Topic: Java If you do not want decimals places for numeric values whose precision has been set (to say 2 decimal places) when it has trailing zeros e.g. Or the printing (which is explained in the question/answers you've linked)? Can a remote machine execute a Linux command? To fix this, only use the DecimalFormat when you are displaying the value. But if you just want to eliminate the .0 from floating point numbers then perhaps this is what you want. There is no difference between integers (12,-12)and floating numbers (12.00). The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". If you need m_interest calculations, keep it as a regular double. Am I applying the methods correctly? A currency instance could work even better: Use BigDecimal instead, which supports the formatting approach you seek. This is exactly what his problem is. How to round a number to n decimal places in Java. Is this variant of Exact Path Length Problem easy or NP Complete. I am working on your solution . I believe the OP only wants to get rid of the .0 in 2.0. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. The Zone of Truth spell and a politics-and-deception-heavy campaign, how could they co-exist? This cookie is set by GDPR Cookie Consent plugin. take answers in python upto 2 decimal places. Save my name, email, and website in this browser for the next time I comment. calendar class in java w3schools; special verdict form example; neon rave bluetooth transmitter. @FlorianSchaetz had exactly what I needed. The number of digits after the decimal point. How to keep two decimals even if the second decimal is a zero? Once it's round it, I know how to print it. Answers. draw a vertical line to the right of the place value digit that. Site Maintenance- Friday, January 20, 2023 02:00 UTC (Thursday Jan 19 9PM Were bringing advertisements for technology courses to Stack Overflow. In algorithms for matrix multiplication (eg Strassen), why do we say n is equal to the number of rows and not the number of elements in both matrices? Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. By clicking Post Your Answer, you agree to our terms of service, privacy policy and cookie policy. Correct me if I am wrong, but this also has the implicit instruction of "round to 6 decimal places" not just "keep 6 decimal places". What's the simplest way to print a Java array? Add a comment. Here is an example: public String formatNumber (int decimals, double number) { StringBuilder sb = new StringBuilder (decimals + 2); sb.append ("#."); for (int i = 0; i < decimals; i++) { sb.append ("0"); } return new DecimalFormat (sb.toString ()).format (number); } Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide. Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide. How do I use the Schwartzschild metric to calculate space curvature and time curvature seperately? By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. It uses expensive divide operations. By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. Read the full article to find the right method for you. java printf leading zeros; how to add zeros after decimal in java; how to remove leading space in java; string format leading zeros; excel remove leading zeros before decimal; . How do you left pad an integer value with zeroes in Java when converting to a string? How to get the current working directory in Java? 2 Answers Sorted by: 2 One way is to use String.format (). You can do it with formatting as follows: System.out.format ("Square of %d is %.0f Square of %d is %.0f", firstNum, firstSquare, secondNum, secondSquare); %d means an integer without decimal places and %.0f means a floating-point number with 0 decimal places as you wanted.