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 8366201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:51:25+00:00 2026-06-09T12:51:25+00:00

I am trying to take a file and split it into 512kb chunks. To

  • 0

I am trying to take a file and split it into 512kb chunks. To calculate the number of chunks, I need to do some basic math. For some reason, I am having some data loss issues. I can’t figure out what I’m doing wrong. I currently have:

int chunkSize = 524288;  // 512kb
int fileByteCount = GetFileSizeInBytes();
decimal result = ((decimal)(fileByteCount)) / ((decimal)(chunkSize));
int packetCount = Math.Ceiling(result);   // Doesn't work.

I can’t use Math.Ceiling because it requires a double. But, I think, I need to use a decimal to do the math. What am I doing wrong? How do I do this basic math operation?

  • 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-06-09T12:51:27+00:00Added an answer on June 9, 2026 at 12:51 pm

    Use integer math:

    int chunkSize = 524288;  // 512kb
    int fileByteCount = GetFileSizeInBytes();
    int packetCount = (fileByteCount + chunkSize - 1) / chunkSize;
    

    Note that a file size should really be long, transferring files larger than 2 gigabytes is not unusual.

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

Sidebar

Related Questions

I am trying to take my Haskell project and split it apart into a
I'm trying to take an image file, do some stuff to it and save
In C#, I'm trying to take some random file selected by a user, and
I am trying to take a CSV file as input and transform it into
So I'm basically just trying to take in some file input, and then take
I am trying to take a rather large CSV file and insert it into
I am trying to take an AES HMAC of a file using the openssl
I am trying to make a program that can take an .mp3 file from
I am trying to use getc(character) to take an element from a file and
While trying to take some arguments for C. I found it really difficult to

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.