How to get decimal value of weight in mini cart?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












How to get decimal value of weight in mini cart.
I need to display only 2 decimals 11.00 instead of 11.0000



enter image description here



enter image description here



enter image description here










share|improve this question























  • you want weight value as like 11.00, right ?
    – Aditya Shah
    1 hour ago










  • yeah its script had written in knockoutjs Aditya Shah
    – trilok kumar
    1 hour ago










  • Can you please add your phtml & js file code here ?
    – Rohan Hapani
    32 mins ago











  • <strong class="product-item-Weight"> <!-- ko if: weight --> <div class="Approx-Weight" data-bind="html: 'Approx Weight : ' + weight * qty "></div> <!-- /ko --> </strong>
    – trilok kumar
    30 mins ago






  • 1




    Yeah :D But, it's knockout. So, It's different que than I gave all answer.
    – Rohan Hapani
    17 mins ago

















up vote
1
down vote

favorite












How to get decimal value of weight in mini cart.
I need to display only 2 decimals 11.00 instead of 11.0000



enter image description here



enter image description here



enter image description here










share|improve this question























  • you want weight value as like 11.00, right ?
    – Aditya Shah
    1 hour ago










  • yeah its script had written in knockoutjs Aditya Shah
    – trilok kumar
    1 hour ago










  • Can you please add your phtml & js file code here ?
    – Rohan Hapani
    32 mins ago











  • <strong class="product-item-Weight"> <!-- ko if: weight --> <div class="Approx-Weight" data-bind="html: 'Approx Weight : ' + weight * qty "></div> <!-- /ko --> </strong>
    – trilok kumar
    30 mins ago






  • 1




    Yeah :D But, it's knockout. So, It's different que than I gave all answer.
    – Rohan Hapani
    17 mins ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











How to get decimal value of weight in mini cart.
I need to display only 2 decimals 11.00 instead of 11.0000



enter image description here



enter image description here



enter image description here










share|improve this question















How to get decimal value of weight in mini cart.
I need to display only 2 decimals 11.00 instead of 11.0000



enter image description here



enter image description here



enter image description here







magento2 magento-2.1.7 mini-cart






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 12 mins ago

























asked 1 hour ago









trilok kumar

1168




1168











  • you want weight value as like 11.00, right ?
    – Aditya Shah
    1 hour ago










  • yeah its script had written in knockoutjs Aditya Shah
    – trilok kumar
    1 hour ago










  • Can you please add your phtml & js file code here ?
    – Rohan Hapani
    32 mins ago











  • <strong class="product-item-Weight"> <!-- ko if: weight --> <div class="Approx-Weight" data-bind="html: 'Approx Weight : ' + weight * qty "></div> <!-- /ko --> </strong>
    – trilok kumar
    30 mins ago






  • 1




    Yeah :D But, it's knockout. So, It's different que than I gave all answer.
    – Rohan Hapani
    17 mins ago

















  • you want weight value as like 11.00, right ?
    – Aditya Shah
    1 hour ago










  • yeah its script had written in knockoutjs Aditya Shah
    – trilok kumar
    1 hour ago










  • Can you please add your phtml & js file code here ?
    – Rohan Hapani
    32 mins ago











  • <strong class="product-item-Weight"> <!-- ko if: weight --> <div class="Approx-Weight" data-bind="html: 'Approx Weight : ' + weight * qty "></div> <!-- /ko --> </strong>
    – trilok kumar
    30 mins ago






  • 1




    Yeah :D But, it's knockout. So, It's different que than I gave all answer.
    – Rohan Hapani
    17 mins ago
















you want weight value as like 11.00, right ?
– Aditya Shah
1 hour ago




you want weight value as like 11.00, right ?
– Aditya Shah
1 hour ago












yeah its script had written in knockoutjs Aditya Shah
– trilok kumar
1 hour ago




yeah its script had written in knockoutjs Aditya Shah
– trilok kumar
1 hour ago












Can you please add your phtml & js file code here ?
– Rohan Hapani
32 mins ago





Can you please add your phtml & js file code here ?
– Rohan Hapani
32 mins ago













<strong class="product-item-Weight"> <!-- ko if: weight --> <div class="Approx-Weight" data-bind="html: 'Approx Weight : ' + weight * qty "></div> <!-- /ko --> </strong>
– trilok kumar
30 mins ago




<strong class="product-item-Weight"> <!-- ko if: weight --> <div class="Approx-Weight" data-bind="html: 'Approx Weight : ' + weight * qty "></div> <!-- /ko --> </strong>
– trilok kumar
30 mins ago




1




1




Yeah :D But, it's knockout. So, It's different que than I gave all answer.
– Rohan Hapani
17 mins ago





Yeah :D But, it's knockout. So, It's different que than I gave all answer.
– Rohan Hapani
17 mins ago











3 Answers
3






active

oldest

votes

















up vote
2
down vote



accepted










For that, You need to add one custom function and pass your precision value and weight value. Add this below code in your html file :



<strong class="product-item-Weight">
<!-- ko if: weight -->
<div class="Approx-Weight" data-bind="html: 'Approx Weight : ' + getWeight(2,weight * qty) ">
</div>
<!-- /ko -->
</strong>


Now, create getWeight() function in your knockout file inside Component.extend :



getWeight : function(precision,WeightValue)
var self = this;
return WeightValue / Math.pow(10, self.precision());
,


Now, refresh your html and knockout js file and check it.



Hope, It maybe helpful for you.





share
















  • 1




    +1 :) i knew you will find
    – Aditya Shah
    5 mins ago










  • Thanks bro :) @AdityaShah
    – Rohan Hapani
    2 mins ago










  • Where should i create getWeight() function in your knockout file inside Component.extend Rohan Hapani
    – trilok kumar
    1 min ago

















up vote
1
down vote













you can use number_format function like this in minicart template file-



number_format($weight, 2, '.', '');





share|improve this answer




















  • script had written in knockoutjs Shashank Kumrawat
    – trilok kumar
    1 hour ago

















up vote
1
down vote













JS:



var value = 11.0000;
var result = value.toFixed(2);
alert(result); // 11.00


PHP:



$value = "11.0000";
$result = bcadd($value , 0, 2);

echo $result ; // 11.00


Update:



You can create a block, you put your js inside, then you bind that block in your knockoutjs



1. <?php $jsBlock = echo $this->getLayout()->createBlock("MagentoFrameworkViewElementTemplate")->setTemplate("html/custom.phtml")->toHtml(); ?>

<script type="text/javascript">
var js_block = <?php echo json_encode($jsBlock)?>;
</script>
2. web/template/somename.html
<div class="name-class" data-bind="html:js_block"></div>

3. custom.phtml
<script type="text/javascript">
var value = 11.0000;
var result = value.toFixed(2);
alert(result); // 11.00
</script>


Update2:





  1. app/design/frontend/Vendor/theme/Magento_Search/view/frontend/templates/form.mini.phtml




    <?php $jsBlock = echo $this->getLayout()->createBlock("MagentoFrameworkViewElementTemplate")->setTemplate("html/custom.phtml")->toHtml(); ?>

    <script type="text/javascript">
    var js_block = <?php echo json_encode($jsBlock)?>;
    </script>




  2. web/template/somename.html




    <div class="name-class" data-bind="html:js_block"></div> 






share|improve this answer






















  • script had written in knockoutjs PRINCE
    – trilok kumar
    1 hour ago










  • Check my update, I don't tested it but I think it should work
    – PRINCE
    59 mins ago










  • web/template/somename.html my file location <div class="name-class" data-bind="html:js_block"></div> here how to get PRINCE
    – trilok kumar
    56 mins ago










  • Look my update2
    – PRINCE
    43 mins ago










  • I am not getting any value as update2 – PRINCE
    – trilok kumar
    38 mins ago










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f246449%2fhow-to-get-decimal-value-of-weight-in-mini-cart%23new-answer', 'question_page');

);

Post as a guest






























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










For that, You need to add one custom function and pass your precision value and weight value. Add this below code in your html file :



<strong class="product-item-Weight">
<!-- ko if: weight -->
<div class="Approx-Weight" data-bind="html: 'Approx Weight : ' + getWeight(2,weight * qty) ">
</div>
<!-- /ko -->
</strong>


Now, create getWeight() function in your knockout file inside Component.extend :



getWeight : function(precision,WeightValue)
var self = this;
return WeightValue / Math.pow(10, self.precision());
,


Now, refresh your html and knockout js file and check it.



Hope, It maybe helpful for you.





share
















  • 1




    +1 :) i knew you will find
    – Aditya Shah
    5 mins ago










  • Thanks bro :) @AdityaShah
    – Rohan Hapani
    2 mins ago










  • Where should i create getWeight() function in your knockout file inside Component.extend Rohan Hapani
    – trilok kumar
    1 min ago














up vote
2
down vote



accepted










For that, You need to add one custom function and pass your precision value and weight value. Add this below code in your html file :



<strong class="product-item-Weight">
<!-- ko if: weight -->
<div class="Approx-Weight" data-bind="html: 'Approx Weight : ' + getWeight(2,weight * qty) ">
</div>
<!-- /ko -->
</strong>


Now, create getWeight() function in your knockout file inside Component.extend :



getWeight : function(precision,WeightValue)
var self = this;
return WeightValue / Math.pow(10, self.precision());
,


Now, refresh your html and knockout js file and check it.



Hope, It maybe helpful for you.





share
















  • 1




    +1 :) i knew you will find
    – Aditya Shah
    5 mins ago










  • Thanks bro :) @AdityaShah
    – Rohan Hapani
    2 mins ago










  • Where should i create getWeight() function in your knockout file inside Component.extend Rohan Hapani
    – trilok kumar
    1 min ago












up vote
2
down vote



accepted







up vote
2
down vote



accepted






For that, You need to add one custom function and pass your precision value and weight value. Add this below code in your html file :



<strong class="product-item-Weight">
<!-- ko if: weight -->
<div class="Approx-Weight" data-bind="html: 'Approx Weight : ' + getWeight(2,weight * qty) ">
</div>
<!-- /ko -->
</strong>


Now, create getWeight() function in your knockout file inside Component.extend :



getWeight : function(precision,WeightValue)
var self = this;
return WeightValue / Math.pow(10, self.precision());
,


Now, refresh your html and knockout js file and check it.



Hope, It maybe helpful for you.





share












For that, You need to add one custom function and pass your precision value and weight value. Add this below code in your html file :



<strong class="product-item-Weight">
<!-- ko if: weight -->
<div class="Approx-Weight" data-bind="html: 'Approx Weight : ' + getWeight(2,weight * qty) ">
</div>
<!-- /ko -->
</strong>


Now, create getWeight() function in your knockout file inside Component.extend :



getWeight : function(precision,WeightValue)
var self = this;
return WeightValue / Math.pow(10, self.precision());
,


Now, refresh your html and knockout js file and check it.



Hope, It maybe helpful for you.






share











share


share










answered 7 mins ago









Rohan Hapani

3,96821459




3,96821459







  • 1




    +1 :) i knew you will find
    – Aditya Shah
    5 mins ago










  • Thanks bro :) @AdityaShah
    – Rohan Hapani
    2 mins ago










  • Where should i create getWeight() function in your knockout file inside Component.extend Rohan Hapani
    – trilok kumar
    1 min ago












  • 1




    +1 :) i knew you will find
    – Aditya Shah
    5 mins ago










  • Thanks bro :) @AdityaShah
    – Rohan Hapani
    2 mins ago










  • Where should i create getWeight() function in your knockout file inside Component.extend Rohan Hapani
    – trilok kumar
    1 min ago







1




1




+1 :) i knew you will find
– Aditya Shah
5 mins ago




+1 :) i knew you will find
– Aditya Shah
5 mins ago












Thanks bro :) @AdityaShah
– Rohan Hapani
2 mins ago




Thanks bro :) @AdityaShah
– Rohan Hapani
2 mins ago












Where should i create getWeight() function in your knockout file inside Component.extend Rohan Hapani
– trilok kumar
1 min ago




Where should i create getWeight() function in your knockout file inside Component.extend Rohan Hapani
– trilok kumar
1 min ago












up vote
1
down vote













you can use number_format function like this in minicart template file-



number_format($weight, 2, '.', '');





share|improve this answer




















  • script had written in knockoutjs Shashank Kumrawat
    – trilok kumar
    1 hour ago














up vote
1
down vote













you can use number_format function like this in minicart template file-



number_format($weight, 2, '.', '');





share|improve this answer




















  • script had written in knockoutjs Shashank Kumrawat
    – trilok kumar
    1 hour ago












up vote
1
down vote










up vote
1
down vote









you can use number_format function like this in minicart template file-



number_format($weight, 2, '.', '');





share|improve this answer












you can use number_format function like this in minicart template file-



number_format($weight, 2, '.', '');






share|improve this answer












share|improve this answer



share|improve this answer










answered 1 hour ago









Shashank Kumrawat

6311136




6311136











  • script had written in knockoutjs Shashank Kumrawat
    – trilok kumar
    1 hour ago
















  • script had written in knockoutjs Shashank Kumrawat
    – trilok kumar
    1 hour ago















script had written in knockoutjs Shashank Kumrawat
– trilok kumar
1 hour ago




script had written in knockoutjs Shashank Kumrawat
– trilok kumar
1 hour ago










up vote
1
down vote













JS:



var value = 11.0000;
var result = value.toFixed(2);
alert(result); // 11.00


PHP:



$value = "11.0000";
$result = bcadd($value , 0, 2);

echo $result ; // 11.00


Update:



You can create a block, you put your js inside, then you bind that block in your knockoutjs



1. <?php $jsBlock = echo $this->getLayout()->createBlock("MagentoFrameworkViewElementTemplate")->setTemplate("html/custom.phtml")->toHtml(); ?>

<script type="text/javascript">
var js_block = <?php echo json_encode($jsBlock)?>;
</script>
2. web/template/somename.html
<div class="name-class" data-bind="html:js_block"></div>

3. custom.phtml
<script type="text/javascript">
var value = 11.0000;
var result = value.toFixed(2);
alert(result); // 11.00
</script>


Update2:





  1. app/design/frontend/Vendor/theme/Magento_Search/view/frontend/templates/form.mini.phtml




    <?php $jsBlock = echo $this->getLayout()->createBlock("MagentoFrameworkViewElementTemplate")->setTemplate("html/custom.phtml")->toHtml(); ?>

    <script type="text/javascript">
    var js_block = <?php echo json_encode($jsBlock)?>;
    </script>




  2. web/template/somename.html




    <div class="name-class" data-bind="html:js_block"></div> 






share|improve this answer






















  • script had written in knockoutjs PRINCE
    – trilok kumar
    1 hour ago










  • Check my update, I don't tested it but I think it should work
    – PRINCE
    59 mins ago










  • web/template/somename.html my file location <div class="name-class" data-bind="html:js_block"></div> here how to get PRINCE
    – trilok kumar
    56 mins ago










  • Look my update2
    – PRINCE
    43 mins ago










  • I am not getting any value as update2 – PRINCE
    – trilok kumar
    38 mins ago














up vote
1
down vote













JS:



var value = 11.0000;
var result = value.toFixed(2);
alert(result); // 11.00


PHP:



$value = "11.0000";
$result = bcadd($value , 0, 2);

echo $result ; // 11.00


Update:



You can create a block, you put your js inside, then you bind that block in your knockoutjs



1. <?php $jsBlock = echo $this->getLayout()->createBlock("MagentoFrameworkViewElementTemplate")->setTemplate("html/custom.phtml")->toHtml(); ?>

<script type="text/javascript">
var js_block = <?php echo json_encode($jsBlock)?>;
</script>
2. web/template/somename.html
<div class="name-class" data-bind="html:js_block"></div>

3. custom.phtml
<script type="text/javascript">
var value = 11.0000;
var result = value.toFixed(2);
alert(result); // 11.00
</script>


Update2:





  1. app/design/frontend/Vendor/theme/Magento_Search/view/frontend/templates/form.mini.phtml




    <?php $jsBlock = echo $this->getLayout()->createBlock("MagentoFrameworkViewElementTemplate")->setTemplate("html/custom.phtml")->toHtml(); ?>

    <script type="text/javascript">
    var js_block = <?php echo json_encode($jsBlock)?>;
    </script>




  2. web/template/somename.html




    <div class="name-class" data-bind="html:js_block"></div> 






share|improve this answer






















  • script had written in knockoutjs PRINCE
    – trilok kumar
    1 hour ago










  • Check my update, I don't tested it but I think it should work
    – PRINCE
    59 mins ago










  • web/template/somename.html my file location <div class="name-class" data-bind="html:js_block"></div> here how to get PRINCE
    – trilok kumar
    56 mins ago










  • Look my update2
    – PRINCE
    43 mins ago










  • I am not getting any value as update2 – PRINCE
    – trilok kumar
    38 mins ago












up vote
1
down vote










up vote
1
down vote









JS:



var value = 11.0000;
var result = value.toFixed(2);
alert(result); // 11.00


PHP:



$value = "11.0000";
$result = bcadd($value , 0, 2);

echo $result ; // 11.00


Update:



You can create a block, you put your js inside, then you bind that block in your knockoutjs



1. <?php $jsBlock = echo $this->getLayout()->createBlock("MagentoFrameworkViewElementTemplate")->setTemplate("html/custom.phtml")->toHtml(); ?>

<script type="text/javascript">
var js_block = <?php echo json_encode($jsBlock)?>;
</script>
2. web/template/somename.html
<div class="name-class" data-bind="html:js_block"></div>

3. custom.phtml
<script type="text/javascript">
var value = 11.0000;
var result = value.toFixed(2);
alert(result); // 11.00
</script>


Update2:





  1. app/design/frontend/Vendor/theme/Magento_Search/view/frontend/templates/form.mini.phtml




    <?php $jsBlock = echo $this->getLayout()->createBlock("MagentoFrameworkViewElementTemplate")->setTemplate("html/custom.phtml")->toHtml(); ?>

    <script type="text/javascript">
    var js_block = <?php echo json_encode($jsBlock)?>;
    </script>




  2. web/template/somename.html




    <div class="name-class" data-bind="html:js_block"></div> 






share|improve this answer














JS:



var value = 11.0000;
var result = value.toFixed(2);
alert(result); // 11.00


PHP:



$value = "11.0000";
$result = bcadd($value , 0, 2);

echo $result ; // 11.00


Update:



You can create a block, you put your js inside, then you bind that block in your knockoutjs



1. <?php $jsBlock = echo $this->getLayout()->createBlock("MagentoFrameworkViewElementTemplate")->setTemplate("html/custom.phtml")->toHtml(); ?>

<script type="text/javascript">
var js_block = <?php echo json_encode($jsBlock)?>;
</script>
2. web/template/somename.html
<div class="name-class" data-bind="html:js_block"></div>

3. custom.phtml
<script type="text/javascript">
var value = 11.0000;
var result = value.toFixed(2);
alert(result); // 11.00
</script>


Update2:





  1. app/design/frontend/Vendor/theme/Magento_Search/view/frontend/templates/form.mini.phtml




    <?php $jsBlock = echo $this->getLayout()->createBlock("MagentoFrameworkViewElementTemplate")->setTemplate("html/custom.phtml")->toHtml(); ?>

    <script type="text/javascript">
    var js_block = <?php echo json_encode($jsBlock)?>;
    </script>




  2. web/template/somename.html




    <div class="name-class" data-bind="html:js_block"></div> 







share|improve this answer














share|improve this answer



share|improve this answer








edited 44 mins ago

























answered 1 hour ago









PRINCE

6,6652935




6,6652935











  • script had written in knockoutjs PRINCE
    – trilok kumar
    1 hour ago










  • Check my update, I don't tested it but I think it should work
    – PRINCE
    59 mins ago










  • web/template/somename.html my file location <div class="name-class" data-bind="html:js_block"></div> here how to get PRINCE
    – trilok kumar
    56 mins ago










  • Look my update2
    – PRINCE
    43 mins ago










  • I am not getting any value as update2 – PRINCE
    – trilok kumar
    38 mins ago
















  • script had written in knockoutjs PRINCE
    – trilok kumar
    1 hour ago










  • Check my update, I don't tested it but I think it should work
    – PRINCE
    59 mins ago










  • web/template/somename.html my file location <div class="name-class" data-bind="html:js_block"></div> here how to get PRINCE
    – trilok kumar
    56 mins ago










  • Look my update2
    – PRINCE
    43 mins ago










  • I am not getting any value as update2 – PRINCE
    – trilok kumar
    38 mins ago















script had written in knockoutjs PRINCE
– trilok kumar
1 hour ago




script had written in knockoutjs PRINCE
– trilok kumar
1 hour ago












Check my update, I don't tested it but I think it should work
– PRINCE
59 mins ago




Check my update, I don't tested it but I think it should work
– PRINCE
59 mins ago












web/template/somename.html my file location <div class="name-class" data-bind="html:js_block"></div> here how to get PRINCE
– trilok kumar
56 mins ago




web/template/somename.html my file location <div class="name-class" data-bind="html:js_block"></div> here how to get PRINCE
– trilok kumar
56 mins ago












Look my update2
– PRINCE
43 mins ago




Look my update2
– PRINCE
43 mins ago












I am not getting any value as update2 – PRINCE
– trilok kumar
38 mins ago




I am not getting any value as update2 – PRINCE
– trilok kumar
38 mins ago

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f246449%2fhow-to-get-decimal-value-of-weight-in-mini-cart%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

List of Gilmore Girls characters

Confectionery