Hi guys i'm looking for a script that separates the thousands with a comma and point decimal 2 with 00 example 2,800,000.00 and that only allow to use from 0 to 9 and comma + point
<div id="item-post-price" class="item-post-price">
<label class="control-label" for="price">
<?php _e('Price', 'ctg_housing'); ?>
</label>
<?php ItemForm::price_input_text(); ?>
</div>
I try already this script
<script type="text/javascript">
$('#price').bind('hide-price', function(){
$('.control-group-price').hide();
});
$('#price').bind('show-price', function(){
$('.control-group-price').show();
});
<?php if(osc_locale_thousands_sep()!='' || osc_locale_dec_point() != '') { ?>
$().ready(function(){
$("#price").blur(function(event) {
var price = $("#price").prop("value");
<?php if(osc_locale_thousands_sep()!='') { ?>
while(price.indexOf('<?php echo osc_esc_js(osc_locale_thousands_sep()); ?>')!=-1) {
price = price.replace('<?php echo osc_esc_js(osc_locale_thousands_sep()); ?>', '');
}
<?php }; ?>
<?php if(osc_locale_dec_point()!='') { ?>
var tmp = price.split('<?php echo osc_esc_js(osc_locale_dec_point())?>');
if(tmp.length>2) {
price = tmp[0]+'<?php echo osc_esc_js(osc_locale_dec_point())?>'+tmp[1];
}
<?php }; ?>
$("#price").prop("value", price);
});
});
<?php }; ?>
</script>
Thanks
i made a php function that convert value to string .
function cnvrt($number)
{
$no = round($number);
$point = round($number - $no, 2) * 100;
$hundred = null;
$digits_1 = strlen($no);
$i = 0;
$str = array();
$wordsWEB = array('0' => '', '1' => 'one', '2' => 'two',
'3' => 'three', '4' => 'four', '5' => 'five', '6' => 'six',
'7' => 'seven', '8' => 'eight', '9' => 'nine',
'10' => 'ten', '11' => 'eleven', '12' => 'twelve',
'13' => 'thirteen', '14' => 'fourteen',
'15' => 'fifteen', '16' => 'sixteen', '17' => 'seventeen',
'18' => 'eighteen', '19' =>'nineteen', '20' => 'twenty',
'30' => 'thirty', '40' => 'forty', '50' => 'fifty',
'60' => 'sixty', '70' => 'seventy',
'80' => 'eighty', '90' => 'ninety');
$digits = array('', 'hundred', 'thousand', 'lakh', 'crore');
while ($i < $digits_1)
{
$divider = ($i == 2) ? 10 : 100;
$number = floor($no % $divider);
$no = floor($no / $divider);
$i += ($divider == 10) ? 1 : 2;
if ($number) {
$plural = (($counter = count($str)) && $number > 9) ? 's' : null;
$hundred = ($counter == 1 && $str[0]) ? '' : null;
$str [] = ($number < 21) ? $wordsWEB[$number] .
" " . $digits[$counter] . $plural . " " . $hundred
:
$wordsWEB[floor($number / 10) * 10]
. " " . $wordsWEB[$number % 10] . " "
. $digits[$counter] . $plural . " " . $hundred;
} else $str[] = null;
}
$str = array_reverse($str);
$result = implode('', $str);
$points = ($point) ? "." . $wordsWEB[$point / 10] . " " . $wordsWEB[$point = $point % 10] : '';
return $result." rupees only";
}
echo cnvrt(9875);
?>
test this function Here..just copy and paste.
i hope this helps.
If you want to display different number formats like german oder english number formats, you can simply do some of the following:
switch (lang) {
case "de":
return value.toString().replace(".", "").replace(",", ".");
case "en":
return value.toString().replace(",", "");
}