Created
April 12, 2019 05:41
-
-
Save epicsagas/0ad6ba929937d4e1399c01efd7d7a3bf to your computer and use it in GitHub Desktop.
Korean won with Korean unit / 한국 금액을 한국어 단위로 처리
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createKoreanWon($price = 0) | |
{ | |
$krw = ''; | |
if($price) { | |
$priceArr = str_split(strrev((string)$price), 4); | |
$unitArr = ['','만','억','조','경']; | |
$count = min(count($priceArr),count($unitArr)); | |
$priceWithUnit = | |
array_combine( | |
array_slice($unitArr, 0, $count), | |
array_slice($priceArr, 0, $count) | |
); | |
foreach(array_reverse($priceWithUnit) as $unit => $price) { | |
$price = intval(strrev($price)); | |
$krw .= ($price > 0) ? $price . $unit : ''; | |
} | |
} | |
return $krw . '원'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment