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

  • Home
  • SEARCH
  • 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 6691087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:42:40+00:00 2026-05-26T05:42:40+00:00

I have rails 3 application and the following problem. I need to calculate a

  • 0

I have rails 3 application and the following problem. I need to calculate a price based on the following:

  • Term range from 1 to 365 days (1 year).
  • Tariffs in a tables which presented in two sections: for one day and for half a month (15 days)

Example 1:

  • Prices: 1 day price = 0.5 and 15 days = 6
  • Term : 45 days.
  • Price: To get the price we devide the number of days by 15 (45/15 = 3) and multiply the result by the tariff for 15 days (3*6 = 18). Final price 18.

Example 2:

  • Prices: 1 day price = 0.5 and 15 days = 6
  • Term : 79 days.
  • Price: To get the price we find the half month period in this case is 45 and again we devide that number by 15 (75/15 = 5) and multiply the result by the tariff for 15 days (5*6 = 30). However there are 4 more days to account for, so we multiple them by the price for a day (4*0.5 = 2). The sum of the two results forms the final price (30+2 = 32).

The period is submited through a from and can be anything from 1 day to 365 days, prices per day and 15 days are stored in a database. My question is how to make the calculations in ruby/rails, so the code always calculates the half month and the reminder if any?
Any help is appreciated.

  • 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-26T05:42:40+00:00Added an answer on May 26, 2026 at 5:42 am

    use the modulo operator:

    79 / 15 # dividing integers performs an euclidian division
    => 5
    
    79 % 15 # gives you the rest from an euclidian division. 
    => 4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in my Rails application's routes file: MyApp::Application.routes.draw do constraints
I have the following code in one of my Rails 3 application views: <ul>
In my Rails 3.2.3 application I have the following code in the application.html.erb to
I have a Rails application that uses ActiveRecordStore for sessions. I need a PHP
I have the following models in my Rails application: class Shift < ActiveRecord::Base has_many
I have a task to develop a rails application following the model for routing.
I have a Rails 2.3 application. I currently have the following validations in my
I have a rails application with the following Models: User (id) Version (id, post_id,
In a rails application I am working on I have the following setup: class
I have Rails application with mounted Engine. #{main_app}/config/routes.rb mount CommentIt::Engine => /talk, :as =>

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.