এই নিবন্ধে, আমরা বুঝতে পারব কিভাবে একটি সংখ্যাকে n থেকে দশমিক স্থান পর্যন্ত বৃত্তাকার করতে হয়। CEIL বা FLOOR ফাংশন ব্যবহার করে দশমিক মানের রাউন্ডিং করা হয়।
নীচে একই -
এর একটি প্রদর্শন রয়েছে৷ইনপুট
ধরুন আমাদের ইনপুট হল −
Input : 3.1415
আউটপুট
কাঙ্খিত আউটপুট হবে −
Output : 3.2
অ্যালগরিদম
Step 1 - START Step 2 - Declare a float variable values namely my_input. Step 3 - Read the required values from the user/ define the values Step 4 – Use the CEIL function to round the number to the required decimal places. In this example we are rounding up to 2 decimal places. Store the result. Step 5- Display the result Step 6- Stop
উদাহরণ 1
এখানে, একটি প্রম্পটের উপর ভিত্তি করে ব্যবহারকারী দ্বারা ইনপুট প্রবেশ করানো হচ্ছে। আপনি আমাদের কোডিং গ্রাউন্ড টুলে এই উদাহরণ লাইভ চেষ্টা করতে পারেন
।
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Scanner;
public class DecimalFormatting {
public static void main(String[] args) {
float my_input;
System.out.println("Required packages have been imported");
Scanner my_scanner = new Scanner(System.in);
System.out.println("A scanner object has been defined ");
System.out.print("Enter the first binary number : ");
my_input = my_scanner.nextFloat();
DecimalFormat roundup_decimal = new DecimalFormat("#.#");
roundup_decimal.setRoundingMode(RoundingMode.CEILING);
System.out.println("The rounded up value of " +my_input + " is ");
System.out.println(roundup_decimal.format(my_input));
}
} আউটপুট
Required packages have been imported A scanner object has been defined Enter the first binary number : 3.1415 The decimal number is defined as 3.1415 The rounded up value of 3.1415 is 3.2
উদাহরণ 2
এখানে, পূর্ণসংখ্যা পূর্বে সংজ্ঞায়িত করা হয়েছে, এবং এর মান অ্যাক্সেস করা হয়েছে এবং কনসোলে প্রদর্শিত হয়েছে।
import java.math.RoundingMode;
import java.text.DecimalFormat;
public class DecimalFormatting {
public static void main(String[] args) {
System.out.println("Required packages have been imported");
double my_input = 3.1415;
System.out.println("The decimal number is defined as " +my_input);
DecimalFormat roundup_decimal = new DecimalFormat("#.#");
roundup_decimal.setRoundingMode(RoundingMode.CEILING);
System.out.println("The rounded up value of " +my_input + " is ");
System.out.println(roundup_decimal.format(my_input));
}
} আউটপুট
Required packages have been imported The decimal number is defined as 3.1415 The rounded up value of 3.1415 is 3.2