highcharts with number_format - php

i'm working with Highcharts, and i'm having some problem with number_format.
formating the number $variable = 1008000 :
number_format($variable, 2,',','.')
the result is: 1.008.000,00 (this is what i need)
but, highcharts transform 1.008.000,00 to 1.008
how can i deal with this problem?

Note that in English the number should be 1,008,000.00
You could either change it in your number_format() call or try changing the decimal point value in Hightcharts (http://www.highcharts.com/ref/#lang)

note one thing, we do not need to set the number format for high chart...
you can pass directly 1008000 it will be auto adjust with this value...
Check this...Good luck
Thanks

Apart from lang parameters http://api.highcharts.com/highstock#lang.thousandsSep you can also use Highcharts.numberFormat() for labels / tooltip which can be used in formatter .
http://api.highcharts.com/highstock#highcharts.numberFormat()
http://api.highcharts.com/highstock#tooltip.formatter

Related

How to display only value on Laravel?

Please help me. how to display only value on Laravel.
when i'm var_dump($data->count_date)
i got like this.
int(347)
how to remove int()?
Thks
php var_dump — Dumps information about a variable, not the variable alone.
$data->count_date is an integer number value, you can use it like any other integer, for example:
$value=$data->count_date+1;
Just do, It will only return the value.
dd($data->count_date);

OpenTBS multiply variable with other variable inside table

I am trying to use the following functionality:
[quote_elements.product.factor;ope=mul:quote_elements.qty]
But all I get is always 0.
if I use:
[quote_elements.product.factor;ope=mul:4]
it works fine and I get 4 times the factor number.
But this is not what I need. I need to multiply dynamically the factor with the quantity. this can be for each row different.
any tips what I am missing here?
Embedded TBS fields does not work in parameter ope.
That why the string « quote_elements.qty » is always converted to 0.
Parameter ope=mul can work only with fixed values.
In order to solve you problem, you can use a custom ondata function. It will enable you to add a calculated column in you record before to merge it.
PHP side:
function f_my_ondata($BlockName, &$CurrRec, $RecNum) {
$CurrRec['my_result'] = $CurrRec['product']['factore'] * $CurrRec['qty'];
}
Template side :
[quote_elements;block=...;ondata=f_my_ondata] // block definition
...
[quote_elements.my_result]

PHP format number before insert into database

i'm using $_POSTto send form values to PHP and then insert into database, i have some inputs for prices values that looks like this:
1.000.000,00 (1 million in BRL "Brazilian Real")
I need to convert it to 1000000.00 (DECIMAL(10,2) to insert into database)
How can i do that using PHP number_format()?
Thanks!
EDIT
If number_format() is not the function i'm looking for, what's best to be using in this case?
Also, i need help finding a solution, even if the user value is 100.000,00
You can not do that with number format, it works other way around.
The thing that you do is bad practice, View layer should send primitive data to Controller - if you are using some advanced javascript component to represent to the user formatted number, that is fine, but underlaying form control should send primitive data, i.e. 10000000.00
Now, if nothing that I have stated to you is not applicable at this particular moment, and having in mind that this format that you have send is fixed (dot for thousand separator, coma for decimal separator), you can clean the value by using simple str_replace.
But, the trick is to replace first dot with empty string, then coma with dot.
str_replace(',', '.',str_replace('.', '', $number));
Got it?
But know that what you are doing is bad approach and wrong implementation, eventually, it will bite you in the a**.
<?php
$number = '1.000.000,00';
$replaced_number = str_replace(array('.',','), array('',''), $number);
echo number_format($replaced_number,2,'.','');
?>
The easiest way is to use str_replace() function:
<?php
$p = '1.000.000,00';
$p = str_replace('.', '', $p);
$p = str_replace(',', '.', $p);
echo $p;
At first replace the (.) and (,) with str_replace by '' and then use t the following function
number_format($replaced_number,$decimal)
If you have a look at php.net you will easily see the right syntax for your goal:
number_format($number,2,'.','')
The first parameter is the number of decimal places that in your case is 2.
The second is the symbol to use for decimal separator and the third is the one to be used for thousands that in your case will be nothing .

PHP Intval() strange behaviour

I am currently trying to resolve a problem with changing the type of a variable in order to be able to do math operations with it. I am trying to enhance a Wordpress plugin called "WooCommerce PDF Invoices & Packing Slips".
There is a variable $item['order_price'], which contains a price with a currency sign. var_dump() of this variable returns string(48)"709 Kč".
When I try to get the integer value using either intval() or casting it via (int), it returns 0.
What could be the solution?
Just try
filter_var($item['order_price'], FILTER_SANITIZE_NUMBER_INT);
I suggest you use at least : trim($item['order_price']);

How to make 2.4212744961175E+18 like 2421274496117503233 in PHP

I am using GoToWebinar API and getting following value A which is correct but i have another function which takes it as parameter and gives customer list.
A = 2.4212744961175E+18
B = 2421274496117503233
Problem is function is not getting value A, if i am using value B its working
Can any one tell me how can i convert A to like B so it will work.
Thanks
<?php $var = sprintf("%f",'2.4212744961175E+18'); ?>
replace %f to your integer if you are not using float
Just run the number through number_format. For example:
$a = number_format(2.4212744961175E+18, 0);
Or start using third party PHP libraries that deal with numbers. BC Math, GMP, Math etc.
Finally got the solution and that large value with + sign was coming due to large integar and PHP 5.3 or less versions have that bug which has been resolved in PHP5.4, i tested on 5.4 version and it gave correct output.
See this link for details
Yea I was having the same issue, looks like you had to add that last argument at the end to make that value a string instead of a float:
$data = json_decode( $jsonString, true, 512, JSON_BIGINT_AS_STRING );

Categories