Convert Currency to The Nearest RM0.05

Malaysia recently introduce a rounding mechanism for trading to remove the need for 1 cent in the market, but with this new implementation it cause us web developer more task to make it work with our current application.

The Rounding Mechanism is a method whereby the total bill amount (including goods and services subject to tax) is rounded upwards or downwards to the nearest multiple of 5 sen. In this regard, total bill amount that ends in 1, 2, 6 and 7 sen will be rounded down while 3, 4, 8 and 9 sen will be rounded up to the nearest multiple of 5 sen.

For example, a total bill amounting to RM82.01 will be rounded down to RM82.00. If it amounts to RM82.04, it will be rounded up to RM82.05.

Source BNM Rounding Mechanism


Here’s two different version if you ever need it:

PHP

Credit Resipi PHP

function nearest_5cent($val) {
    return round($val*20)/20;
}

JavaScript

var nearest_5cent = function(val) {
	return (Math.round(val*20)/20);
}
Posted in Code Snippet, How-To, JavaScript, PHP | 2 Comments

2 Responses to Convert Currency to The Nearest RM0.05

  1. fauzi says:

    HALLO BRO,
    CAMNBER NAK BUAT CONVERT RM0.05 TU KEPADA TEXT PULA.
    CONTOH RM LIMA SEN SAHAJA

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>