Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Automatyczny przecinek, Dzielenie liczby na xxx.xxx.xxx
My4tic
post
Post #1





Grupa: Zarejestrowani
Postów: 260
Pomógł: 0
Dołączył: 4.08.2005

Ostrzeżenie: (0%)
-----


Witam,

Mam taki skrypt:

  1. var x = 9631444;
  2. var y = 42;
  3.  
  4. function start(){
  5. x = x + y;
  6. document.getElementById('x').innerHTML = x;
  7. setTimeout("start()", 5000);
  8. }


...i chcialbym aby liczba byla dzielona np. na 9.631.444 a nie 9631444.

Pzdr
Go to the top of the page
+Quote Post
revyag
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 2 258
Pomógł: 16
Dołączył: 21.09.2004
Skąd: Kielce

Ostrzeżenie: (0%)
-----


Nie wiem czy da się to zrobić bez konwersji na stringa. Wyglądałoby to tak (trochę zamotane:))
Dzieli tą liczbę na 3 częściowe kawałki, na początku jest 1 lub dwuczęściowy string.
Kod
<script type="text/javascript">
var x = 9631444;
var y = 42;
function start(){
    
    x = x + y;

    var strarr = Array();
    
    var j = 0;
    
    for(var i = String(x).length; i > 2; i-=3) {
        strarr[j++] = String(x).substr(i-3,3);
    }
    
    strarr[j] = String(x).substr(0,i);
    
    strarr.reverse();
    
    
    document.getElementById('x').innerHTML = strarr+'<br />';
    setTimeout("start()", 5000);
}  
</script>
Go to the top of the page
+Quote Post
My4tic
post
Post #3





Grupa: Zarejestrowani
Postów: 260
Pomógł: 0
Dołączył: 4.08.2005

Ostrzeżenie: (0%)
-----


Wszystko gra :-)

Dzięki za pomoc.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 16.09.2025 - 04:16