Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
Boostrap ngb-rating half of star

I am using ng-rating to display avg value of score. The problem is when average value is like 3.97. Ng-rating still displays it as 3 stars. How can I make it to display like half of a star? my html:

<div style="font-size: x-large; color: orange;"><ngb-rating [max]="5" [(rate)]="overallScore" [readonly]="false"></ngb-rating></div>

Example for 3.67 value: star

Edit: While trying solution from bootstrap site 4 hearts filling of heart is a bit square?

Edit2:

Template:

<ng-template #t let-fill="fill">
        <span class="star" [class.full]="fill === 100">
          <span class="half" [style.width.%]="fill">⭐</span>⭐
        </span>
    </ng-template>

I have changed code to css

 .star {
        position: relative;
        display: inline-block;
        font-size: 3rem;
        color: #d3d3d3;
    }
    .star.full {
        color: #ffa600;
    }
    .star.half {
        position: absolute;
        display: inline-block;
        overflow: hidden;
        color: #ffa600;
    }

and it gives that result: stars

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

For the custom template with decimals you can use following:

<ng-template #scoreTemplate let-fill="fill">
    <span class="star" [class.full]="fill === 100">
      <span class="half" [style.width.%]="fill">⭐</span>⭐
    </span>
</ng-template>

<ngb-rating max="5"
  [(rate)]="overallScore"
  [readonly]="true"
  [starTemplate]="scoreTemplate">
</ngb-rating>

but you also need the styles:

.star {
  position: relative;
  display: inline-block;
  font-size: 3rem;
  color: #d3d3d3;

  &.full {
    color: #ffa600;
  }

  &.half {
    position: absolute;
    display: inline-block;
    overflow: hidden;
    color: #ffa600;
  }
}

For just half a star and not all decimals you can use:

<ng-template #scoreTemplate let-fill="fill">
    <span class="star" [class.full]="fill < 50">
      <span class="half" [style.width.%]="fill >= 50 ? 50 : 0">⭐</span>⭐
    </span>
</ng-template>

Also, you can replace the emoji with your custom icon.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!