Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    Dec 2005
    Messaggi
    24

    stranezza arrotondamento Mysql

    la funzione di Mysql round(10.5,0) o anche solo round(10.5) sul server hosting restituisce 11, in locale invece restituisce 10, nelle guide ho trovato che fino a 0.5 round dovrebbe arrotondare per difetto, oltre per eccesso. In ogni caso rimane la differenza tra locale e hosting sulla stessa funzione e calcolo, potrebbe dipendere dalla versione di Mysql ? al momento non mi viene in mente a cos'altro poter attribuire tale differenza non da poco :master:

  2. #2
    Utente di HTML.it L'avatar di luca200
    Registrato dal
    Apr 2002
    Messaggi
    4,120
    Before MySQL 5.0.3, the behavior of ROUND() when the argument is halfway between two integers depends on the C library implementation. Different implementations round to the nearest even number, always up, always down, or always toward zero. If you need one kind of rounding, you should use a well-defined function such as TRUNCATE() or FLOOR() instead.

    As of MySQL 5.0.3, ROUND() uses the following rules depending on the type of the first argument:

    *

    For exact-value numbers, ROUND() uses the “round half up” or “round toward nearest” rule: A value with a fractional part of .5 or greater is rounded up to the next integer if positive or down to the next integer if negative. (In other words, it is rounded away from zero.) A value with a fractional part less than .5 is rounded down to the next integer if positive or up to the next integer if negative.
    *

    For approximate-value numbers, the result depends on the C library. On many systems, this means that ROUND() uses the "round to nearest even" rule: A value with any fractional part is rounded to the nearest even integer.

  3. #3
    io ci ho perso 2 gg dietro questa cosa un paio di anni orsono, non mi tornavano dei conti e non capivo il motivo


  4. #4
    Utente di HTML.it
    Registrato dal
    Dec 2005
    Messaggi
    24
    ok grazie

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.