Help me with a code that multiplies each value stored in a rangeslider by 10 and display the output in a specific place
I'm in need of a code that multiplies each value assigned to a rangeslider by (any number) and display the output in a seperate place.
Related
I am using cakephp 2.5 making a Costing Sheet where i calculate values by using javascript function, which give value in decimal places, and if i round the value then there is different in total for exact amount,
So i want to show value set by javascript upto only 2 decimal but want to save all decimal values into database i.e. MySql ,
<td colspan="2" >
<?php echo $this->Form->input('Particular.particular_value'.$i, array('name'=>'particular_value[]','label'=>false, 'class'=>'form-control', 'type'=>'number','min'=>'0','step'=>'.001','default' => "0",'autocomplete' => 'off','value'=>isset($this->data['Particular'][$index]['particular_bare_pipe_rate_per_mt_value'])?$this->data['Particular'][$index]['particular_bare_pipe_rate_per_mt_value'] :'0')); ?>
</td>
and
$('#CostValue').val(precisionRound(pbcrv, 0));
function precisionRound(number, precision) {
var factor = Math.pow(10, precision);
return Math.round(number * factor) / factor;
}
when i input values then it calculate by predefined formulas i round them using precisionRound function , but when i make total it always vary from total that is made by excel sheet,
I want something like EXCEL sheet number function, where i show value upto 2 decimal on front for showing but when i calculate or save values in to database it should be saved with all decimal values.
Blue background input boxes are input boxes which are calling js function for further calculation, grey background input boxes are disabled for input (they are based on first inputs) is place where i want to display 2 decimal place value.
Like that--
Actual Value - 2664.267779
show Value on front - 2664
Save in database - 2664.267779
For a number of reasons you should consider not relying on the client side calculations to POST the data to the server and then store it. A more robust solution would be to POST the inputs to the calculation and do the calculation again on the server.
The reasons for this are many, e.g.
a) An error in your client side calcs could easily see NaN posted to the server in error.
b) If this calculation was (for example) calculating a total price for X items of the same type that you were ordering and showing the total, a canny user would be able to edit the input field prior to posting and possibly pay a smaller amount for their goods.
For those that read (b) and think 'naw - no-one would do that', I have seen it in the wild...
I have two textboxes in which I can write numerical values which are used to get the min and max value of Y axis in a chart.
For example, if I have the values set on min = 0 and max = 100, the Y-axis of the chart will be from 0 to 100. If I change max = 50, the chart is rendered for Y-axis from 0 to 50.
The problem is if I delete the value and don't write anything in place, the chart disappears. What I want to do is if the value is deleted and nothing is written after, to keep that value and don't do anything to the chart.
This is the html:
<span class="min-max">
Max:</br>
<input type="number" ng-change="$ctrl.updateY()" ng-model="$ctrl.maxValue"></br>
Min:</br>
<input type="number" ng-change="$ctrl.updateY()" ng-model="$ctrl.minValue"></br>
</span>
This is the js function:
updateY() {
const maxNumber = Number(this.maxValue);
const minNumber = Number(this.minValue);
this.lineView.chart.axis.range({max: {y: maxNumber}, min: {y: minNumber}});
}
Any suggestions?
Since Angular has two way data binding, when the user deletes the text in the box, that has also changed the value in $scope.
You_could_ keep a copy; perhaps by using onBeforeChange() and onAfterChange().
BUT, if you say "if the text is empty, insert the previous value", then you are going to confuse & annoy a user who had deleted the current value prior to inserting a new one.
I would suggest that you ng-sho/hide a message, based on the input text being empty, that says "you can't see any chart because the X-axis value is blank".
I'm working with the DateRangeSlider for the first time and I'm using it as a TimeSlider: FiddleJS
The problem is that when a button is pressed the min bounded value, or the max one, should change, but it doesn't do anything for min or broke the slider when pressing the button for max.
The default values are for January 1st:
var minDateStr = "2014-01-01T00:00:00Z";
var maxDateStr = "2014-01-01T23:59:00Z";
to display the hours:minutes for one day and the button bounded values are from January 5th:
min :new Date("2016-01-05T05:00:00Z")
Is there a way to change the min and max bounds properly to "2016-01-05T05:00:00Z" without changing the default values (January 1st)?
I'm not sure if the task you're trying to achieve is practical or is even possible.
According to the documentation, slider values can be changed by code only at initialization. It means that even if you set either min2 or max2 to either end to the bound, then the slider can't "jump" there to properly represent the area you've originally selected. This is not practical.
Moreover, in the documentation, I couldn't find any way to get the values at which the labels are "standing". Apparently, min2 and max2 are not modified but serve rather as regular and unmodified JS constants.
You can modify the bounds but if you desire to do so, you have to use HTML inputs for dates. It doesn't seem to be possible by defining new bounds with the selected range.
I am building this little calculator where there is only one input field and when user submits the data, I want form to do 2 calculations and display the results in separate divs.
In the first div, I want to whatever user puts in the input area and multiply it by 0.017 (result goes into first div). For the second calculation, I want to multiply the whatever value was put into the input field by 0.170 and display the result in a separate div. Please see the image for visual rep.
Essentially you are creating two values (one calculation for each field) then setting the inside of the display elements (the DIVs) to the values of the calculations:
var someNumber = 10;
var someNumberAfterCalculationOne = someNumber % 4;
var someNumberAfterCalculationTwo = someNumber - someNumberAfterCalculationOne;
document.getElementById("lt_input").innerHTML = someNumberAfterCalculationOne;
document.getElementById("kg_input").innerHTML = someNumberAfterCalculationTwo;
Here is an example of how you might accomplish this:
http://jsfiddle.net/nmbwamtd/3/
This approach is a little ugly, but should get you through to the next step.
This following code for get back to vat value from percentage value and amount value using java script but its not accuracy.
var vat=((25*100)/447);
vat=vat.toFixed(1);
OK, to help, you need to specify the details you are working with. What is the VAT rate? Are you working from the gross value (includes the VAT), or the nett value (excludes the VAT).
var nVatRate = 0.2;// This is the rate of VAT in the UK at present, 20%
function VatAmountFromGross(nGrossAmount){
return nGrossAmount / (1 + (1 / nVatRate));
}
function VatAmountFromNet(nNetAmount){
return nNetAmount * (1 + nVatRate);
}
So, change the VAT rate to match yours, which I am guessing is 25% (0.25).
Using "toFixed(1)" will ensure the value is fixed to 1 decimal place - usually you need two decimal places for VAT. You will also have rounding issues if you are summing values, and these cannot be helped.
Instead of this:
var vat=((25*100)/447);
vat=vat.toFixed(1);
You should be using exact total amount:
var vat=((24.585*100)/447);
vat=vat.toFixed(3);
What you should do while saving the values in the database is round of every value to three decimal, be it vat, percentage or total amount..and to present it to the user/client you can round it off to one or two decimal places.