Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.text.DecimalFormat;
import java.text.NumberFormat;

import java.util.Locale;

public class Main {
    public static String convertToCurrency(float value) {
        DecimalFormat format = new DecimalFormat("#.##");
        try {
            value = Float.parseFloat(format.format(value));
        } catch (Exception e) {
            e.printStackTrace();
        }
        NumberFormat defaultFormat = NumberFormat.getCurrencyInstance(Locale.CANADA);
        return defaultFormat.format(value);
    }
}