Jump to content
Sign in to follow this  
Gilbert

Fylle på med 0-er (nuller)

Recommended Posts

mener å huske at det er en php-funksjon som teller antall tegn i en variabel, og hvis det er færre enn oppgi i argumentet fyller den på med ekstra nuller. Stemmer det?

 

$tall = funksjon('123',4);

 

$tall = 0123;

Share this post


Link to post

Vet ikke helt, men du kan jo lett lage en slik funksjon da..

 

<?php

function Siffer($Tall, $Siffer) {
 $Tallstreng = floatval($Tall);
 $Sifferantall = strlen(intval($Tallstreng));
 for ($i = $Sifferantall; $i < $Siffer; $i++) {
   $Tallstreng = '0'.$Tallstreng;
 }
 return $Tallstreng;
}

echo Siffer(15.736, 4);  // gir 0015.736

?>

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...