Support

Account

Home Forums ACF PRO Insert dots and $ sign if is a number

Solving

Insert dots and $ sign if is a number

  • Hello!

    I need help with a text input field, because I need to add $ if is a number and dots if is thousand ($123.456)

    Here is my code

    <?php if ( have_rows( 'valores' ) ) : ?>
    <?php while ( have_rows( 'valores' ) ) : the_row(); ?>
    <?php the_sub_field( 'valor1' ); ?>
    <?php the_sub_field( 'valor2' ); ?>
    <?php endwhile; ?>
    <?php endif; ?>

    I’ll appreciate any help
    Thank you very much!

  • 
    $valor1 = get_sub_field('valor1');
    if (intval($valor1) == $valor1) {
      $valor1 = '$'.number_format(intval($valor1, ',', '.'));
    }
    echo $valor1;
    
  • Thanks John!

    But the results is $0

    Any idea?

    Thx

  • What is the value that is in the field that you’re trying to convert?

  • Just a number: 260000

  • Post the code that you ended up with

  • valor1= 260000 –> $260.000
    valor2= example –> example

    valor1 and valor2 can be number or text.

    <?php if ( have_rows( 'valores' ) ) : ?>
    <?php while ( have_rows( 'valores' ) ) : the_row(); ?>
    <?php the_sub_field( 'valor1' ); ?>
    <?php the_sub_field( 'valor2' ); ?>
    <?php endwhile; ?>
    <?php endif; ?>

    Thx

  • I want to know what you changed your code to after my first post, you re-posted the original code.

  • With the next code, I have $0

    <?php $valor1 = get_sub_field('valor1');
    if (intval($valor1) == $valor1) {
    	$valor1 = '$'.number_format(intval($valor1, ',', '.'));
    }
    echo $valor1;
    ?>

    With the next code, I have: 260000$0

    <?php if ( have_rows( 'valores' ) ) : ?>
    <?php while ( have_rows( 'valores' ) ) : the_row(); ?>
    	<?php
    	$valor1 = the_sub_field('valor1');
    	if (intval($valor1) == $valor1) {
    		$valor1 = '$'.number_format(intval($valor1, ',', '.'));
    	}
    	echo $valor1;
    	?>
    <?php endwhile; ?>
    <?php endif; ?>

    Thx

  • 
    if ( have_rows( 'valores' ) ) :
    	while ( have_rows( 'valores' ) ) : 
    		the_row();
    		$value = get_field('valor1');
    		if ($value == intval($value)) {
    			$value = '$'.number_format(intval($value, ',', '.'));
    		}
    		echo $value;
    		$value = get_field('valor2');
    		if ($value == intval($value)) {
    			$value = '$'.number_format(intval($value, ',', '.'));
    		}
    		echo $value;
    	endwhile;
    endif;
    
  • Hello John,

    It still doesn’t work =(

    with this: $value = get_field(‘valor1’);
    I have: $0

    With this: $value = the_sub_field(‘valor1’);
    I have: 260000$0

    Any idea?

    By the way, thank you very much for your time

  • 
    if ( have_rows( 'valores' ) ) :
    	while ( have_rows( 'valores' ) ) : 
    		the_row();
    		$value = get_sub_field('valor1');
    		if ($value == intval($value)) {
    			$value = '$'.number_format(intval($value, ',', '.'));
    		}
    		echo $value;
    		$value = get_sub_field('valor2');
    		if ($value == intval($value)) {
    			$value = '$'.number_format(intval($value, ',', '.'));
    		}
    		echo $value;
    	endwhile;
    endif;
    
Viewing 12 posts - 1 through 12 (of 12 total)

The topic ‘Insert dots and $ sign if is a number’ is closed to new replies.