6

I have a serialized object in a field. I now need to output a float-value. Since the site has 2 languages (german/english) I now need to format the float-number based on the current language.

$value = 123456789.01;
// Language = english
print the_format_function($value); # => 123456789.01

// Lanuage = german
print the_format_function($value); # => 123.345.789,01

I'm lookin for the_format_funtion();.

6

There is a format_number API module, which may eventually handle this for you. And possibly will make it into D8.

For the moment I think the function you are looking for is number_format()

5
  • unfortunately format_number is only for D6. Apr 11 '11 at 15:08
  • You can still use the php function number_format() Apr 11 '11 at 15:16
  • Yup… used it. But had to build my own language-logic around it. Was hoping for some stuff that is built into d7. Apr 11 '11 at 21:36
  • I would have thought there would be too. Wordpress does?!? Apr 12 '11 at 8:14
  • For this specific behaviour, creating logic around the number_format() function is the way to go. And note that English-speaking countries use the comma as the decimal mark for the thousands separator, so the example provided was wrong.
    – Pere
    Dec 6 '13 at 15:22
-1

There is a number_format function in native php, so you can do in your drupal template:

print number_format($value, 2, ',', '.'); # => 123.345.789,01

see http://php.net/manual/es/function.number-format.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.