Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6651429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:00:36+00:00 2026-05-26T01:00:36+00:00

i have: @ = 1 # = 0,5 % = 0 max = 10

  • 0

i have:

@ = 1
# = 0,5
% = 0

max = 10

for example if i have: 3 then should show me:

@@@$$$$$$$

if i have 3,5 :

@@@#$$$$$$

etc

if i have 3,99 then = 3,5
if i have 3,49 then = 3,0

etc

how can i use this with foreach or for?

for whole number i can make:

$number = 8;
$one = 10 - $number;
$three = 0 + $number;

and

for($i=1;$i <= $one){
  echo "@";
}

for($i=1;$i <= $three){
  echo "$";
}

but how is the best solution if $number = 3,57

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:00:37+00:00Added an answer on May 26, 2026 at 1:00 am

    If I’ve understood what you’re after, this should do what you want:

    <?php
    
    function printItOut($number) {
        $s = '';
        for ($i = 0; $i < 10; $i++) {
            if ($i < $number%10) {
                $s .= '@';
            } else if ($i < ($number+0.5)%10) {
                $s .= '#';
            } else {
                $s .= '$';
            }
        }
        return $s;
    }
    
    
    echo printItOut(3.49), "\n";
    echo printItOut(3.5), "\n";
    echo printItOut(3.99), "\n";
    echo printItOut(4), "\n";
    

    Outputs:

    @@@$$$$$$$
    @@@#$$$$$$
    @@@#$$$$$$
    @@@@$$$$$$
    

    Inside the for loop, I using the modulus operator to find the integer remainder of dividing $number by 10. So 3%10 gives a result of 3, 3.49%10 also results in 3.

    In the first ‘else if’ block, I’m checking whether the number is 0.5 or more, since (3.49+0.5) is 3.99, and 3.99%10 is 3; but 3.5+0.5 is 4, and 4%10 is 4.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I have a table with max 2000 rows, the user should search up
I have rather big form where a user can choose any number of parameters
Someone inputs www.example.com/3/ I have a model with a charfield that I can slugify.
One question that I have long asked myself is in object oriented programming,how should
This should be an easy one to track down...but it isn't proving that way
I have models (simplified example): class Group(models.Model): name = models.CharField(max_length = 32) class Person(models.Model):
I have a model: class Example(models.Model): unique_hash = models.CharField(max_length=32,unique=True) content = models.FileField(upload_to='source',blank=True,verbose_name=HTML Content File)
Does python have the ability to create dynamic keywords? For example: qset.filter(min_price__usd__range=(min_price, max_price)) I
I have a xml which is max 3 levels deep. Now by using C#
I have a table which has two varchar(Max) columns Column 1 Column 2 -----------------------

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.