Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9323385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:19:46+00:00 2026-06-19T04:19:46+00:00

Function not working for prefix with 8[any numbers]. input: 970 output:$9.70 input: 870 output:$870

  • 0

Function not working for prefix with 8[any numbers].

input: 970 output:$9.70
input: 870 output:$870
input: 800 output:$800

function toMoney( $val, $symbol = '$', $r = 2 ) {
    $n = $val; 
    $c = is_float($n) ? 1 : number_format( $n , $r );
    $d = '.';
    $t = ',';
    $sign = ( $n < 0 ) ? '-' : '';
    $i = $n = number_format( abs( $n ), $r ); 
    $j = ( ( $j = $i.length ) > 3 ) ? $j % 3 : 0; 

   return  $symbol.$sign .( $j ? substr( $i, 0, $j) + $t : '').preg_replace('/(\d{3})(?=\d)/',"$1" + $t,substr($i,$j)) ;
}

Function taken from: Money conversion not worked

The above error rectified in the below

  function toMoney( $val, $symbol = '$', $r = 2 ) {
        $n = $val; 
        $c = is_float($n) ? 1 : number_format( $n , $r );
        $d = '.';
        $t = ',';
        $sign = ( $n < 0 ) ? '-' : '';
        $i = $n = number_format( abs( $n ), $r ); 
        $j = ( ( $j = strlen($i) ) > 3 ) ? $j % 3 : 0; 

       return  $symbol.$sign .( $j ? substr( $i, 0, $j) + $t : '').preg_replace('/(\d{3})(?=\d)/',"$1" + $t,substr($i,$j)) ;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T04:19:47+00:00Added an answer on June 19, 2026 at 4:19 am

    If I understand well, you want the two last numbers to be cents?

    so why don’t just do :

    $val = number_format(intval(substr($val,0,strlen($val)-2)),).'.'.substr($val,-2);
    

    the first substr will just forget the two last digits and then will be formated with only thousand separator.
    the second substr just take the two last numbers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$(document).ready(function() not working after page refresh in ie 6.Is there any problem to use?Whether
The following JQuery function is not working entirely. IE 7 processes both alerts, but
Window.open javascript function is not working in Mozilla, but working in other browsers, here
Can anyone tell me why this function is not working ? for(var i=1;i<=12;i++) {
I am using this function but it is not working. I'm using StoryBoard and
jquery change function on dropdown is not working at my application and working at
In Titanium mobile indexOf function of String is not working properly. console.log( test2.indexOf( /tes/i
Why is my mkdir not working within the if(is_dir) function but it is working
My jquery code It's not working when $(a).on(hover,function(){$(this).css(background,#ccc);},function(){$(this).css(background,#fff)}); But is working when $(a).hover(function(){$(this).css(background,#ccc);},function(){$(this).css(background,#fff)}); How
I call the following function with a mouseover event but it's not working. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.